Sign in to follow this  
Followers 0
Zohar

[Solved] Is there some WaitForAllKeysUp() function? For Knowing when All Keys have been Released

8 posts in this topic

#1 ·  Posted (edited)

Hello

I have a HotKey which is Ctrl-Alt-5, and when pressing it it calls a certain function.

This function needs to run, in a way that no key is pressed when it starts.

When a user presses this HotKey, it is possible that he will release the Ctrl or the Alt key slowly,

meaning, the function will start running already, and one of those keys is still down.

Therefore I need some WaitForAllKeysUp() function.

What is the best way to create it,

Or,

Does one exist already?

Thank you

Edited by Zohar

Share this post


Link to post
Share on other sites



Dim $tBuff, $pBuff
Dim $aRet

$tBuff = DllStructCreate('byte[256]')
$pBuff = DllStructGetPtr($tBuff)

$aRet = DllCall('user32.dll', 'int', 'GetKeyboardState', 'ptr', $pBuff)

If $aRet[0] Then
    For $i = 1 To 256
        ConsoleWrite(DllStructGetData($tBuff, 1, $i) & @LF)
    Next
    
    ; 0x31 + 1
    If BitAND(DllStructGetData($tBuff, 1, 50), 0x80) Then ConsoleWrite('Key "1" is pressed' & @LF)
EndIf

Then you get the status of all the 256 VK_*.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

very hard to understand anything from your code, authenticity.

as usual.

thanks but no thanks.

If anyone else can help me, I'd really appreciate it.

Authenticity: I would really appreciate it if you ignore all my posts, and simply don't answer them.

Edited by Zohar

Share this post


Link to post
Share on other sites

You can try this:

#include <Misc.au3>
Global $hDLL = DllOpen("user32.dll") ; Open DLL for faster calls

HotKeySet("^!s", "_YourHotKey")

While True ; Replace this with your main script code
    Sleep(1000)
WEnd

Func _YourHotKey()
    While _IsPressed("11", $hDLL) Or _IsPressed("12", $hDLL) ; See if Control or Alt is held
        Sleep(10)
    WEnd

    ; Keys released, begin function code here

EndFunc   ;==>_YourHotKey


[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites

very hard to understand anything from your code, authenticity.

as usual.

thanks but no thanks.

If anyone else can help me, I'd really appreciate it.

Authenticity: I would really appreciate it if you ignore all my posts, and simply don't answer them.

Should everyone who could answer your questions ignore your posts?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Or if the function is really small/quick, you can enable BlockInput at its start and disable when you're done.

By the way, that GetKeyboardState seemed like a good idea, but several VK are enabled in my testing, even when I'm not pressing any keys. Strange, check it out :

#include <Array.au3>

Dim $arraystate[257]
Dim $tBuff, $pBuff
Dim $aRet

$tBuff = DllStructCreate('byte[256]')
$pBuff = DllStructGetPtr($tBuff)

$aRet = DllCall('user32.dll', 'int', 'GetKeyboardState', 'ptr', $pBuff)

If $aRet[0] Then
    For $i = 1 To 256
        $arraystate[$i] = DllStructGetData($tBuff, 1, $i)
        Next
   _ArrayDisplay ($arraystate, "State of keyboard")
EndIf

Share this post


Link to post
Share on other sites

Or if the function is really small/quick, you can enable BlockInput at its start and disable when you're done.

By the way, that GetKeyboardState seemed like a good idea, but several VK are enabled in my testing, even when I'm not pressing any keys. Strange, check it out :

#include <Array.au3>

Dim $arraystate[257]
Dim $tBuff, $pBuff
Dim $aRet

$tBuff = DllStructCreate('byte[256]')
$pBuff = DllStructGetPtr($tBuff)

$aRet = DllCall('user32.dll', 'int', 'GetKeyboardState', 'ptr', $pBuff)

If $aRet[0] Then
    For $i = 1 To 256
        $arraystate[$i] = DllStructGetData($tBuff, 1, $i)
        Next
   _ArrayDisplay ($arraystate, "State of keyboard")
EndIf
If you mean that some of the values are 1 then that is the toggled state I think. Try changing the caps lock and compare the results for element 21.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

@ martin

Cool, so this is useful after all, just needs more ground work to only compare usual keys and ignore some. Then you can BitOR them and compare to 1, good work Authenticity.

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