Jump to content

[Solved] Show a ContextMenu in response to a HotKey


Zohar
 Share

Recommended Posts

I've improved it again - I think I solved a few issues some have pointed out:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=..\icons\Diary.ico
#AutoIt3Wrapper_outfile=Context.exe
#AutoIt3Wrapper_UseUpx=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
Opt("TrayIconHide", 1)
#include <Misc.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>

HotKeySet("{ESC}", "Terminate")
$dll = DllOpen("user32.dll")
$Form1  = GUICreate("", 110, 22, 193, 80, BitOR($WS_POPUP, $WS_EX_MDICHILD,$WS_EX_TOOLWINDOW))
$List_1 = GUICtrlCreateCombo("", 0, 0, 100, 22)
GUICtrlSetData($List_1, "Notepad|Calculator|Word|FireFox|SciTE","")
$lable_1 = GUICtrlCreateLabel("X", 101, 4, 9, 22)
WinSetOnTop($Form1, "", 1)
GUISetState(@SW_Hide)

While 1
    $Msg = GUIGetMsg(0)
    select
        Case _IsPressed("02", $dll) and _IsPressed("11", $dll)
            Context()
            while 2
                $Msg2 = GUIGetMsg(0)
                Select 
                    Case $Msg2 = $GUI_EVENT_CLOSE
                        Exit
                    Case _IsPressed("02", $dll) and _IsPressed("11", $dll)
                        GUISetState(@SW_Hide)
                        exitloop
                    Case $Msg2 = $lable_1
                        GUISetState(@SW_Hide)
                        exitloop                        
                    Case $Msg2 = $List_1
                    $G = GUICtrlRead($List_1)
                    If $G = "Notepad" then 
                        GUISetState(@SW_HIDE)
                        Run("Notepad.exe")
                        ExitLoop
                    endif
                    If $G = "Calculator" then 
                        GUISetState(@SW_HIDE)
                        Run("Calc.exe")
                        ExitLoop
                    endif
                    If $G = "Word" then 
                        GUISetState(@SW_HIDE)
                        Run("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE")
                        ExitLoop
                    endif   
                    If $G = "FireFox" then 
                        GUISetState(@SW_HIDE)
                        Run("C:\Program Files\Mozilla Firefox\firefox.exe")
                        ExitLoop
                    endif   
                    If $G = "SciTE" then 
                        GUISetState(@SW_HIDE)
                        Run("C:\Program Files\AutoIt3\SciTE\SciTE.exe")
                        ExitLoop
                    endif   
                EndSelect   
            WEnd
        Case $Msg = $GUI_EVENT_CLOSE
            Exit            
    EndSelect
WEnd

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

Func Context()
    $m = MouseGetPos()
    WinMove($Form1, "", $m[0], $m[1])
    GUICtrlSetData($List_1, "","")
    GUICtrlSetData($List_1, "Notepad|Calculator|Word|FireFox|SciTE","")
    GUISetState(@SW_SHOW,$Form1)
EndFunc   ;==>Context
Edited by Volly
Link to comment
Share on other sites

cool

but are you sure the game doesn't lose focus?

technically, a Tooltip is a window..

a small one, with no "X" on the corner, but still a window :]

It's not a window, it's a tooltip :P

I tested it and it doesn't steam focus, but most DirectX games constantly paint over the screen so it tends to get drawn over.

Also, feel free to use just .NET. Like you said, people think what they are using is the best, so ...

Edited by Inverted
Link to comment
Share on other sites

porting the source code of AutoIt from C++ to C# should not be too hard, since the 2 languages have similar syntax,

and C# offers much easier coding, much nicer set of classes to help the developer, etc etc.

.NET is with us since 2001,

it's now 2009..

I don't understand why the makers of AutoIt choose not to enjoy all the benefits and speed of coding that C# offers.

I think I'm correct in saying it is made in C++, though it may be written in C#. What you have to understand is what you think is enjoyable may not be to someone else. There are folks who love Python, and those who hate it. Some like .NET, some don't. It is one's own taste is what we are discussing here. So by you saying you don't understand why AutoIt is what it is, well, to answer it is simple. Jon wanted it that way.

For what AutoIt does, it does it well. It is a simple language to learn and for many AutoIt enthusiast, (such as myself) we enjoy what we can do with it. We like to see what we can make it do, and frequently are quite creative in what we come up with. Many folks who are AutoIt enthusiast also code in other languages. I code in several: .NET, WinBatch, DOS, Javascript, just to name a few. Most I'm not that good at, but that is OK. The point here is simply this: Coding is a art. (and a dark art at that).

Saying that, it is what you like, and not what should be dictated to you on what is best to write in and what to do. You can look at a script and sometimes tell who the author was simply by the style. For example - GaryFrost always declares his variables in an AutoIt script. It is what he likes to do. Nothing wrong with that. For myself, I only declare them when needed usually. This is simply a matter of style.

I hope this makes it a bit clearer on why AutoIt is the way it is.

P.S. Thanks to your first post in this thread, I now have a new tool on my PC that I enjoy having. Thank you!

Link to comment
Share on other sites

Heh, nice context lol, I like my new context menu this way now.... heh ;]

If you could so something like delay it so if another context menu (like the desktop one which always hide it) is initialized it won't hide it. I thought about maybe few pixels higher but sometimes the context menu of the focused window get calculated to fit the screen and opened above or below the mouse position. Yeah... annoying. But I still like the idea.

Link to comment
Share on other sites

OK, I think this will work. I notice it doesn't work well on certain windows like Windows Explorer, but it does work well on others.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=..\icons\Diary.ico
#AutoIt3Wrapper_outfile=Context.exe
#AutoIt3Wrapper_UseUpx=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
Opt("TrayIconHide", 1)
#include <Misc.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>

HotKeySet("{ESC}", "Terminate")
$dll = DllOpen("user32.dll")
$Form1  = GUICreate("", 100, 22, 193, 80, BitOR($WS_POPUP, $WS_EX_MDICHILD,$WS_EX_TOOLWINDOW))
$List_1 = GUICtrlCreateCombo("", 0, 0, 100, 22)
GUICtrlSetData($List_1, "Notepad|Calculator|Word|FireFox|SciTE","")
WinSetOnTop($Form1, "", 1)
GUISetState(@SW_Hide)

While 1
    $Msg = GUIGetMsg(0)
    select
        Case _IsPressed("02", $dll) and _IsPressed("11", $dll)
            Context()
            while 2
                $Msg2 = GUIGetMsg(0)
                Select 
                    Case $Msg2 = $GUI_EVENT_CLOSE
                        Exit
                    Case _IsPressed("01", $dll) and WinActive($Form1) = 0
                        GUISetState(@SW_Hide)
                        exitloop                        
                    Case $Msg2 = $List_1
                    $G = GUICtrlRead($List_1)
                    If $G = "Notepad" then 
                        GUISetState(@SW_HIDE)
                        Run("Notepad.exe")
                        ExitLoop
                    endif
                    If $G = "Calculator" then 
                        GUISetState(@SW_HIDE)
                        Run("Calc.exe")
                        ExitLoop
                    endif
                    If $G = "Word" then 
                        GUISetState(@SW_HIDE)
                        Run("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE")
                        ExitLoop
                    endif   
                    If $G = "FireFox" then 
                        GUISetState(@SW_HIDE)
                        Run("C:\Program Files\Mozilla Firefox\firefox.exe")
                        ExitLoop
                    endif   
                    If $G = "SciTE" then 
                        GUISetState(@SW_HIDE)
                        Run("C:\Program Files\AutoIt3\SciTE\SciTE.exe")
                        ExitLoop
                    endif   
                EndSelect   
            WEnd
        Case $Msg = $GUI_EVENT_CLOSE
            Exit            
    EndSelect
WEnd

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

Func Context()
    $m = MouseGetPos()
    WinMove($Form1, "", $m[0], $m[1])
    GUICtrlSetData($List_1, "","")
    GUICtrlSetData($List_1, "Notepad|Calculator|Word|FireFox|SciTE","")
    GUISetState(@SW_SHOW,$Form1)
EndFunc   ;==>Context
Link to comment
Share on other sites

Heh, nice context lol, I like my new context menu this way now.... heh ;]

If you could so something like delay it so if another context menu (like the desktop one which always hide it) is initialized it won't hide it. I thought about maybe few pixels higher but sometimes the context menu of the focused window get calculated to fit the screen and opened above or below the mouse position. Yeah... annoying. But I still like the idea.

OK, I think I fixed that, and made it a bit better - I changed the context function so that the winmove command now will park the combo list right above the regular context menu. Try this and let me know what you think:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=..\icons\Diary.ico
#AutoIt3Wrapper_outfile=Context.exe
#AutoIt3Wrapper_UseUpx=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
Opt("TrayIconHide", 1)
#include <Misc.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>

HotKeySet("{ESC}", "Terminate")
$dll = DllOpen("user32.dll")
$Form1  = GUICreate("", 100, 22, 193, 80, BitOR($WS_POPUP, $WS_EX_MDICHILD,$WS_EX_TOOLWINDOW))
$List_1 = GUICtrlCreateCombo("", 0, 0, 100, 22)
GUICtrlSetData($List_1, "Notepad|Calculator|Word|FireFox|SciTE","")
WinSetOnTop($Form1, "", 1)
GUISetState(@SW_Hide)

While 1
    $Msg = GUIGetMsg(0)
    select
        Case _IsPressed("02", $dll) and _IsPressed("11", $dll)
            Context()
            while 2
                $Msg2 = GUIGetMsg(0)
                Select 
                    Case $Msg2 = $GUI_EVENT_CLOSE
                        Exit
                    Case _IsPressed("01", $dll) and WinActive($Form1) = 0
                        GUISetState(@SW_Hide)
                        exitloop                        
                    Case $Msg2 = $List_1
                    $G = GUICtrlRead($List_1)
                    If $G = "Notepad" then 
                        GUISetState(@SW_HIDE)
                        Run("Notepad.exe")
                        ExitLoop
                    endif
                    If $G = "Calculator" then 
                        GUISetState(@SW_HIDE)
                        Run("Calc.exe")
                        ExitLoop
                    endif
                    If $G = "Word" then 
                        GUISetState(@SW_HIDE)
                        Run("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE")
                        ExitLoop
                    endif   
                    If $G = "FireFox" then 
                        GUISetState(@SW_HIDE)
                        Run("C:\Program Files\Mozilla Firefox\firefox.exe")
                        ExitLoop
                    endif   
                    If $G = "SciTE" then 
                        GUISetState(@SW_HIDE)
                        Run("C:\Program Files\AutoIt3\SciTE\SciTE.exe")
                        ExitLoop
                    endif   
                EndSelect   
            WEnd
        Case $Msg = $GUI_EVENT_CLOSE
            Exit            
    EndSelect
WEnd

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

Func Context()
    $m = MouseGetPos()
    WinMove($Form1, "", $m[0], $m[1]-22)
    GUICtrlSetData($List_1, "","")
    GUICtrlSetData($List_1, "Notepad|Calculator|Word|FireFox|SciTE","")
    GUISetState(@SW_SHOW,$Form1)
EndFunc   ;==>Context
Link to comment
Share on other sites

What you have to understand is what you think is enjoyable may not be to someone else.

Volly,

If you go with your friend to an IceCream shop, and you choose strawberry and he chooses banana,

then that's a matter of taste.

But If you drive a car, and your friend drives a horse, then one of you is not being so efficient.

P.S. Thanks to your first post in this thread, I now have a new tool on my PC that I enjoy having. Thank you!

I'm glad (:

BTW if you upload a screenshot of its last look, it can be nice :]

Edited by Zohar
Link to comment
Share on other sites

Volly,

If you go with your friend to an IceCream shop, and you choose strawberry and he chooses banana,

then that's a matter of taste.

But If you drive a car, and your friend drives a horse, then one of you is not being so efficient.

I'm glad (:

BTW if you upload a screenshot of its last look, it can be nice :]

Some people still like the horse better!

Enough of that...Otherwise we will be beating a dead horse...

To get a screenshot, just run the last script I posted. Then you see it in ACTION, not just a pic!

But, seeing how you want a pic...here you are. Enjoy!

Link to comment
Share on other sites

Now to add a separate question - what would be cool is to figure out a way to have it so the combo will either be on the top or the bottom of the regular context menu depending on where in the vertical plane the mouse is. If you notice when the mouse is located on the bottom of the screen, the Combo will be covered by the regular context menu. I tried last night to solve the problem but I didn't have much luck. AutoIt Window Info would not provide me with information on the context menu, so I'm not sure on how to get it's size and location. If I could get that, then it would be a simple matter of putting the combo in the correct spot. Any ideas?

Edit - AutoIt window Info will show SOME context menus, but not all of them.

Edited by Volly
Link to comment
Share on other sites

so your combobox opens in addition to the application's own contextmenu?

why is that necessary?

why not open just your combobox alone, in response to a key for example?

it would spare you from the need to align it above/below the contextmenu.

Regarding getting info about the contextmenu's window parameters,

I've had this problem too..

I tried finding info about it,

and then tried again,

and then tried even again,

but did not succeed (:

Edited by Zohar
Link to comment
Share on other sites

Most people will use their mouse in the normal way to get a context menu. Saying that, they will RIGHT click with the mouse. Asking them to press F7, well that is awkward. Having them press a key with their left hand while RIGHT clicking with the mouse is easier to do. Now if this is strange to you, then by all means set it to your taste. The example I have shown works fine IMHO.

Now a second way you can look at the problem is to figure out the registry keys to turn off ALL context menus. Saying that, look here:

http://www.windowsnetworking.com/nt/registry/rtips43.shtml

Once you have shut it off, you can then make what I designed work off the RIGHT click so that it shows up by itself.

Link to comment
Share on other sites

OK

:P

it's not strange that you open it via RightClick,

but it is strange that you have it opened, and in addition the ContextMenu is opened(when you did not want it even..)

:]

Well, I do not wish to disable the context menus I have now. I use them frequently. I just wanted to add to them across all applications.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...