Sign in to follow this  
Followers 0
icywind

Keypress detection

4 posts in this topic

Hi all,

Is there a way for autoit to detect a certain key(let's say "a"), to know whether its pressed(held down) ?

I need to make a function that executes certain command if its held down and otherwise.

B)

Share this post


Link to post
Share on other sites



make a hotkey for it,

HotKeySet("{a}", "hotkey_1")

Func hotkey_1()

your command here

EndFunc


Share this post


Link to post
Share on other sites

or IsPressed


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

To elaborate on MSLx Fanboy's suggestion

$keys = StringSplit("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "")
$dll = DllOpen('user32.dll')
While 1
    Sleep(250)
    If _IsPressed("23", $dll) Then
        MsgBox(0, "_IsPressed", "End Key Pressed")
        ExitLoop
    EndIf
    For $x = 1 To $keys[0]
        If _IsPressed(Hex(Asc($keys[$x]),2)) Then
            MsgBox(0, "key pressed", $keys[$x])
        EndIf
    Next
WEnd
DllClose($dll)


Func _IsPressed($s_hexKey, $v_dll = 'user32.dll')
; $hexKey must be the value of one of the keys.
; _Is_Pressed will return 0 if the key is not pressed, 1 if it is.
    Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey)
    If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc  ;==>_IsPressed
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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