Sign in to follow this  
Followers 0
autoITkinect

hold down a key

2 posts in this topic

hi all of autoIT developer

is there any function to hold down a key?

i want to hold down left direction key until i hold down right key it will release the left key?

i use it to make a controller for racing game.

thanks a lot before

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

HotKeySet("l", "HoldLeftKey") ;Can't use {LEFT} for some reason?
HotKeySet("{ESC}", "_Exit")

While 1
    Sleep(100)
WEnd

Func HoldLeftKey()
    While 1
        Send("{LEFT}")
        Sleep(100)
        If _IsPressed(27) Then ExitLoop
    WEnd
EndFunc

Func _IsPressed($sHexKey, $vDLL = 'user32.dll')
    Local $a_R = DllCall($vDLL, "short", "GetAsyncKeyState", "int", '0x' & $sHexKey)
    If @error Then Return SetError(@error, @extended, False)
    Return BitAND($a_R[0], 0x8000) <> 0
EndFunc

Func _Exit()
    Exit
EndFunc

Edited by rogue5099

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