Search code examples
autohotkey

Show Gui Menu with Double Tapping


i have this code for context menu ( its working perfectly )

Details

  • when i hit V => it will send V
  • when i double tap V => it will show up context menu commands
;-------- Layout

Menu, ps_context, Add, Normal, blending_normal_command
Menu, ps_context, Add,
Menu, ps_context, Add, Cancel, close_context


;-------- Hotkey

; Double Tap V = Context Menu 
; Single Tap = Send V

$v::
If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < 400)
Menu, ps_context, Show
else
Send v
return


;------- Command

blending_normal_command: 
Send, {shift down}{alt down}{n down}
Send, {shift up}{alt up}{n up}
return

close_context:
return

Result : Sample

i have no problem with context menu. but when it comes to gui menu and apply same code above it just doesnt work.here's the code for gui i posted 2 code for comparison ( GUI menu & context menu ).is there a workaround to make the below code to make it work? currently double tapping V doesnt do anything but single tapping works

;-------- Hotkey

; Double Tap V = Gui Menu
; Single Tap = Send V

$v::
If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < 400)
Gui, blend_custom_layer:Show
else
Send v
return


;-------- Layout

CoordMode, Mouse, Screen
MouseGetPos, XposA, YposA
XposA-=+0
YposA-=+0

Gui, blend_custom_layer: Font, s9,Segoe UI
Gui, blend_custom_layer:Color, EEAA99

Gui, blend_custom_layer:Add, Button, x0 y0 w20 h20 BackgroundTrans gclosewanrmenu, ✘
Gui, blend_custom_layer:Add, Button, x21 y0 w200 h20  BackgroundTrans gnormal_blend_layer_command, Normal

Gui blend_custom_layer:+LastFound +AlwaysOnTop +ToolWindow
WinSet, TransColor, EEAA99
Gui blend_custom_layer:-Caption
Gui, blend_custom_layer:Show, x%XposA% y%YposA% h500 w500, menus
return



;------- Command

normal_blend_layer_command:
    Gui, blend_custom_layer:Submit
        send {alt down}{shift down}{n down}
        send {alt up}{shift up}{n up}
        Sleep, 50
        Gui, blend_custom_layer:Show 
    Return

closewanrmenu:
Gui, blend_custom_layer:Destroy
return


Solution

  • Why do some lines in my script never execute?

    Any lines you want to execute immediately when the script starts should appear at the top of the script, prior to the first hotkey, hotstring, or Return. For details, see auto-execute section.

    If you want that code to be executed after you press the hotkey, put it in a labeled subroutine and call it from your hotkey subroutine.

    #NoEnv
    #SingleInstance Force
    
    ;-------- Layout
    
    CoordMode, Mouse, Screen
    ; MouseGetPos, XposA, YposA
    ; XposA-=+0
    ; YposA-=+0
    
    Gui, blend_custom_layer: Font, s9,Segoe UI
    Gui, blend_custom_layer:Color, EEAA99
    
    Gui, blend_custom_layer:Add, Button, x0 y0 w20 h20 BackgroundTrans gclosewanrmenu, ✘
    Gui, blend_custom_layer:Add, Button, x21 y0 w200 h20  BackgroundTrans gnormal_blend_layer_command, Normal
    
    Gui blend_custom_layer:+LastFound +AlwaysOnTop +ToolWindow
    WinSet, TransColor, EEAA99
    Gui blend_custom_layer:-Caption
    ; Gui, blend_custom_layer:Show, x%XposA% y%YposA% h500 w500, menus
    
            RETURN   ; === end of auto-execute section ===
    
    
    ;------- Command
    
    normal_blend_layer_command:
        Gui, blend_custom_layer:Submit
        send {alt down}{shift down}{n down}
        send {alt up}{shift up}{n up}
        Sleep, 50
        Gui, blend_custom_layer:Show 
    Return
    
    closewanrmenu:
        ; If you destroy the gui you won't be able to rebuild it by double tapping V 
        Gui, blend_custom_layer:hide
    return
    
    ;-------- Hotkey
    
    ; Double Tap V = Context Menu 
    ; Single Tap = Send V
    
    $v::
        If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < 400)
        {
            MouseGetPos, mX, mY
            Gui, blend_custom_layer:Show, x%mX% y%mY%
        }
        else
            Send v
    return