Sign in to follow this  
Followers 0
yehia

if key held down

6 posts in this topic

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

Share this post


Link to post
Share on other sites

hmmm strange never returns 1

maybe its vista ?

Please post a part from your code to see when returns 1 and when returns 0.


When the words fail... music speaks

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
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

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