Sign in to follow this  
Followers 0
fmen

On demand menu launcher

5 posts in this topic

I am embarrassed to post the small bit of code I came up with so would appreciate any help or direction.

My goal is to create a menu launcher that pops up with a right click of the mouse at the top, bottom, or sides of the screen, and then disappears until it is needed again.

Something like the excellent runit (www.magister-lex.at/RUNit).

Maybe someone already wrote it but my searches were not successful. Thanks.

Opt("SendKeyDelay", 0)
Opt("WinTitleMatchMode", 2)


#include <GUIConstants.au3>

$pos = MouseGetPos()
If $pos[1]=0 Then
GUICreate("Gui", 50, 100, $pos[0],$pos[1], $WS_POPUP,  BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))

$b = GuiCtrlCreateButton("Go", -1, -1, 50, 17)

;;;;;;;;;;;;RIGHT CLICK MENU;;;;;;;;;;;;;;;;;;;;;

$bcontext = GUICtrlCreateContextMenu($b)
$bexit = GUICtrlCreateMenuitem("Exit",$bcontext)
GUISetState()

While 1

$msg = GUIGetMsg()
If $msg = $bexit Then ExitLoop
Wend

endif

Share this post


Link to post
Share on other sites



I am embarrassed to post the small bit of code I came up with so would appreciate any help or direction.

My goal is to create a menu launcher that  pops up with a right click of the mouse at the top, bottom, or sides of the screen, and then disappears until it is needed again.

Something like the excellent runit  (www.magister-lex.at/RUNit).

Maybe someone already wrote it but my searches were not successful. Thanks.

<{POST_SNAPBACK}>

Is this what you want? It's not the way I would organize the code, but I left it as close as possible to your code.

The sleep is to reduce the processor usage. Without it, the processor usage will be 100%.

And you need to place the mouse test in a loop (The While/Wend) else the mouse position will only be tested once.

After the Exit choice you have to delete the Gui else it stays visible.

opt("SendKeyDelay", 0)
opt("WinTitleMatchMode", 2)

#include <GUIConstants.au3>

While 1
    $pos = MouseGetPos()
    If $pos[1] = 0 Then
        $MyGui = GUICreate("Gui", 50, 100, $pos[0], $pos[1], $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
        
        $b = GUICtrlCreateButton("Go", -1, -1, 50, 17)
        
       ;;;;;;;;;;;;RIGHT CLICK MENU;;;;;;;;;;;;;;;;;;;;;
        
        $bcontext = GUICtrlCreateContextMenu($b)
        $bexit = GUICtrlCreateMenuItem("Exit", $bcontext)
        GUISetState()
        
        While 1
            $msg = GUIGetMsg()
            If $msg = $bexit Then 
                GUIDelete($MyGui)
                ExitLoop
            EndIf
        WEnd
    EndIf
    Sleep(100)
WEnd

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Here is a popup menu that slides in from the right along the righthand side of the desktop when the desktop has the focus. it is activated by pressing the {home} key on the keyboard.

This demo uses less than 7% of the CPU. I prefer this popup menu because it hasn't interfered with other applications thus far.

#NoTrayIcon 
#include <GUIConstants.au3>
Opt("GuiOnEventMode", 1) 
$Menupos = 1
$GuiWidth = 150
$GuiHeight = 500
$xPos = (@DesktopWidth) 
$yPos = (@DesktopHeight - $GuiHeight) / 2
;$Button_1A = "button_1A"
;$Button_1B = "button_1B"

;Main Gui
$Gui = GUICreate("Gui", 150, 500, $xPos, $yPos, $WS_POPUP, $WS_EX_TOOLWINDOW)
GUISetBkColor (0)
GUISetState()

;ButtonA
$ButtonA = GUICtrlCreateButton ( "ButtonA", 25, 20 ,100 ,30) 
GUICtrlSetOnEvent($ButtonA, "ButtonA_Pressed")
;GUICtrlSetImage ( $Button_1A, "C:\Icons\ButtonA.ico" )
GUISetState() 

;ButtonB
$ButtonB = GUICtrlCreateButton ( "ButtonB", 25, 50 ,100 ,30) 
GUICtrlSetOnEvent($ButtonB, "ButtonB_Pressed")
GUISetState() 

;ButtonC
$ButtonC = GUICtrlCreateButton ( "Terminate", 25, 450 ,100 ,30) 
GUICtrlSetOnEvent($ButtonC, "Terminate")
GUISetState() 

HotKeySet("{Home}","Menu_Open")
HotKeySet("{End}","Terminate")

While 1
Sleep(10)
WEnd

;Functions 
Func Menu_Open ()
$Menupos = 2
$GuiWidth = 150
$xPos = (@DesktopWidth) 
HotKeySet("{Home}","None")
While $xPos > (@DesktopWidth - $GuiWidth)
  $xPos = $xPos - 2
  WinMove("Gui", "", $xPos, $yPos, 150, 500)
  Sleep (0)
Wend
HotKeySet("{home}" , "Menu_Close")
EndFunc

Func Menu_Close ()
$Menupos = 1
$GuiWidth = 150
$xPos = (@DesktopWidth - $GuiWidth) 
HotKeySet("{Home}","None")
While $xPos < (@DesktopWidth)
  $xPos = $xPos + 2
  WinMove("Gui", "", $xPos, $yPos, 150, 500)
  Sleep (0)
Wend
HotKeySet("{Home}" , "Menu_Open")
EndFunc

Func None ()

EndFunc

Func ButtonA_Pressed()
  MsgBox(4096,"control", "ButtonA pressed")   
EndFunc

Func ButtonB_Pressed()
  MsgBox(4096,"control", "ButtonB pressed")   
EndFunc

Func Terminate ()
  If $Menupos = 1 Then
  
  Else
     $GuiWidth = 150
     $xPos = (@DesktopWidth - $GuiWidth) 
     HotKeySet("{Home}","None")
        While $xPos < (@DesktopWidth)
           $xPos = $xPos + 2
           WinMove("Gui", "", $xPos, $yPos, 150, 500)
           Sleep (0)
        Wend  
  EndIf
  Exit 0  
EndFunc

I'm not the originator of the code. I got it from Nova.

Edited by PerryRaptor

Share this post


Link to post
Share on other sites

Oh, I forgot to mod the script...Needs a GuiDelete command in the Terminate() function in case the desktop resolution is re-sized.

Share this post


Link to post
Share on other sites

This is way more than I had hoped for. Thank you so much.]

Share this post


Link to post
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
Sign in to follow this  
Followers 0