Jump to content

if key held down


yehia
 Share

Recommended Posts

im trying to find a udf same as _istoggled but for ordinary letters

like sends true if any key is held down until its up again

can anyone help me with this?

Try this function:

Func GetKeyState($VK_Code)
    Local $a_Return = DllCall("user32.dll","short","GetKeyState","int",$VK_Code)
    If $a_Return[0] < -126 Then
        Return 1   ;Key is pressed
    Else
        Return 0   ;Key is released
    EndIf
EndFunc

When the words fail... music speaks.

Link to comment
Share on other sites

Msgbox(0,"",GetKeyState(41)) ;... for the A key

Func GetKeyState($VK_Code)
    Local $a_Return = DllCall("user32.dll","short","GetKeyState","int",$VK_Code)
    If $a_Return[0] < -126 Then
        Return 1   ;Key is pressed
    Else
        Return 0   ;Key is released
    EndIf
EndFunc

oh found it it needs ASCII characters not HEX

but still is there any function that tells that there is no key pressed now?

Edited by yehia
Link to comment
Share on other sites

Msgbox(0,"",GetKeyState(41)) ;... for the A key

Func GetKeyState($VK_Code)
    Local $a_Return = DllCall("user32.dll","short","GetKeyState","int",$VK_Code)
    If $a_Return[0] < -126 Then
        Return 1   ;Key is pressed
    Else
        Return 0   ;Key is released
    EndIf
EndFunc

oh found it it needs ASCII characters not HEX

but still is there any function that tells that there is no key pressed now?

I write a simple example for you:

While 1
    If GetKeyState(65) = 1 Then; key A
        TrayTip("GetKeyState","PRESSED",1)
    Else
        TrayTip("GetKeyState","RELEASED",1)
    EndIf
    Sleep(20)
WEnd

Func GetKeyState($VK_Code)
    Local $a_Return = DllCall("user32.dll","short","GetKeyState","int",$VK_Code)
    If $a_Return[0] < -126 Then
        Return 1  ;Key is pressed
    Else
        Return 0  ;Key is released
    EndIf
EndFunc

When the words fail... music speaks.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...