Autohotkey Keyboard – How to Override Keyboard State

autohotkeykeyboard

Is there a way to tell an autohotkey action (subroutine) to release the Alt key despite its trigger is Alt + X ?? here is my code…

!x::
sleep 100
it does some clicks and drags here (work fine)
return

but despite the sleep 100 in my code, sometimes when I press the Alt + X if I manually let the alt pressed the script will do an Alt Click, instead of only a Click which does a completely different thing.

I know I could increase the delay (sleep 100), or set AHK to wait until the alt key is realeased, but none of these would help cuz this script will be run several times continuously, so I prefer to hold down the Alt and press down/up the x several times in order to run it multiple times continuosly.

So I need a way to block temporarily the keyboard, or set the script to release the alt key, so autohotkey won't recognize my finger is still pressing the Alt key while executing the script several times.

I need something similar to this…

BlockInput, MouseMove
BlockInput, On

btw I have tried both, they don't work.

EDIT>>>>>

This is my function to click and drag…

AR4clickDnABmoveClickUpCDfn(ParamA, ParamB, ParamC, ParamD)
{
    If AR4togWorkbMode
    {
        AR4workbModeFn()    ;   Since this fn is used to click n drag panels, after disabling AR4workbMode I won't enable it back, cuz is supposed I need to see the Panel I'm draging afterward
        AR4togWorkbMode := !AR4togWorkbMode ;   So AR4retWorkbMode doesn't need to be set, but AR4togWorkbMode does
        Sleep 200
    }

        MouseGetPos X, Y
        BlockInput, On
        ;   BlockInput, MouseMove
        Sleep 50

        MouseMove, ParamA, ParamB
        Click down
        Sleep 50

        Loop 10
        {
            MouseMove, -1, 1, 100, R
        }

        Sleep 40
        MouseMove, ParamC, ParamD, 100
        Click Up

        BlockInput, Off
        ;   BlockInput, MouseMoveOff
        MouseMove %X%, %Y%
}

Then I in other subroutine !x run a subroutine which will click on a panel and call the click and drag function, in order to drag the panel, this is it..

#If WinActive("ahk_class ArtRage 3") or WinActive("ahk_class ToolWindow")

<!x::
;   Lalt & x::
If !AR4togToolSetsNear  ;   will run the first time the hotkey is pressed cuz the toggle var is not set yet
{
    Sleep 220
    AR4clickDnABmoveClickUpCDfn(AR4toolSetsX0 + AR4toolSetsSetGapXX, AR4toolSetsY0 + 10, AR4toolSetsNearX, AR4toolSetsNearY)
    AR4togToolSetsNear := !AR4togToolSetsNear
    Sleep 20
    WinActivate, ahk_class ArtRage 3
}
Else
{
    Sleep 220
    AR4clickDnABmoveClickUpCDfn(AR4toolSetsNearX, AR4toolSetsNearY, AR4toolSetsX0 + AR4toolSetsFarDifXX, AR4toolSetsY0 + AR4toolSetsFarDifYY)
    AR4togToolSetsNear := !AR4togToolSetsNear
    Sleep 20
    WinActivate, ahk_class ArtRage 3
}
Return

#If

BUT, since this subroutine trigger contains Lalt if I press and hold down Alt while pressing and releasing X multiple times in order to call the subroutine multiple times. Then AHK sript will send Alt Click and Drag and not only Click and Drag the former will actually rotate de panel, while the later will move it, I want to move it, not to rotate it, but on the other hand I need to press and hold ALT in order to run the subroutine multiple times, How can I do??

How can I make AHK to see the Alt keyboard as release while is been pressed manually by me?

Hope some super user could help me out, thanks advanced.

Best Answer

; Trigger an action (subroutine) by releasing the left Alt key, 
; without losing its native function as modifier key:

LAlt up:: 
if (A_PriorKey = "LAlt")
    Send a               ; do sth
return


; Trigger another action by releasing the left Alt key 
; in a key combination:

LAlt & x:: Send b       ; do sth else
; or:
; <!x:: Send b          ; <! means LAlt