Zohar Posted June 11, 2009 Share Posted June 11, 2009 (edited) HelloI 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 March 3, 2012 by Zohar Link to comment Share on other sites More sharing options...
Authenticity Posted June 11, 2009 Share Posted June 11, 2009 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_*. Link to comment Share on other sites More sharing options...
Zohar Posted June 11, 2009 Author Share Posted June 11, 2009 (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 June 11, 2009 by Zohar Link to comment Share on other sites More sharing options...
Skruge Posted June 11, 2009 Share Posted June 11, 2009 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] Link to comment Share on other sites More sharing options...
martin Posted June 11, 2009 Share Posted June 11, 2009 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. Link to comment Share on other sites More sharing options...
Inverted Posted June 11, 2009 Share Posted June 11, 2009 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 Link to comment Share on other sites More sharing options...
martin Posted June 11, 2009 Share Posted June 11, 2009 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. Link to comment Share on other sites More sharing options...
Inverted Posted June 11, 2009 Share Posted June 11, 2009 @ 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now