Zohar Posted August 13, 2021 Share Posted August 13, 2021 Hi all I have this function that I use for years, that checks if all Modifier Keys are up: Func KeyBoard_WaitForModifierKeysUp() While(_IsPressed("10") Or _IsPressed("11") Or _IsPressed("12") Or _IsPressed("5B") Or _IsPressed("5C")) ;Shift,Ctrl,Alt,LWin,RWin Sleep(50) WEnd EndFunc It uses the _IsPressed() function, and calls it 5 times on each run. While it works very well, I am curious If it's possible to achieve the same functionality, via another function, with only a single call. For example, a function that returns a bit-set, with 1 it for every modifier key, and then you test the bits.. I assume there isn't a built-in AutoIt function that does it, so maybe there's a Windows API function that can do it? Thank you Link to comment Share on other sites More sharing options...
Danp2 Posted August 13, 2021 Share Posted August 13, 2021 Have you looked into using _WinAPI_GetKeyboardState? TheXman and Zohar 1 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Zohar Posted August 13, 2021 Author Share Posted August 13, 2021 Thank you Danp2 Looks interesting - I will test it. It returns a 256Byte array, is there a chance that there's also a function just for Modifier Keys, instead for All Keys like the current one? Link to comment Share on other sites More sharing options...
Danp2 Posted August 13, 2021 Share Posted August 13, 2021 Maybe... but that's something you would need to research yourself. 😉 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Zohar Posted August 13, 2021 Author Share Posted August 13, 2021 OK then, thank you very much. Link to comment Share on other sites More sharing options...
Gianni Posted August 15, 2021 Share Posted August 15, 2021 a possible way #include <WinAPISys.au3> ; _WinAPI_GetKeyboardState fails if there is not a GUI $hGUI = GUICreate("Test _WinAPI_GetKeyboardState") GUISetState() KeyBoard_WaitForModifierKeysUp() ; returns when Shift,Ctrl,Alt,LWin,RWin ar all UP MsgBox(0, '', "All modifier Keys are Up") Func KeyBoard_WaitForModifierKeysUp() Local $aKeyboardState Do $aKeyboardState = StringRegExp(StringTrimLeft(DllStructGetData(_WinAPI_GetKeyboardState(), 1), 2), "\w{2}", 3) ConsoleWrite("Debug: " & $aKeyboardState[16] & ' ' & $aKeyboardState[17] & ' ' & $aKeyboardState[18] & ' ' & $aKeyboardState[91] & ' ' & $aKeyboardState[92] & @LF) Sleep(50) Until (Not (BitAND(0x80, BitOR( _ "0x" & $aKeyboardState[16], _ ; Shift "0x" & $aKeyboardState[17], _ ; Ctrl "0x" & $aKeyboardState[18], _ ; Alt "0x" & $aKeyboardState[91], _ ; LWin "0x" & $aKeyboardState[92])))) ; RWin EndFunc ;==>KeyBoard_WaitForModifierKeysUp Zohar 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Zohar Posted August 16, 2021 Author Share Posted August 16, 2021 Thank you very much Chimp. Can you please explain the RegExp line? What does "\w{2}" do? Link to comment Share on other sites More sharing options...
Gianni Posted August 16, 2021 Share Posted August 16, 2021 6 hours ago, Zohar said: Thank you very much Chimp. You are welcome 6 hours ago, Zohar said: Can you please explain the RegExp line? What does "\w{2}" do? ... have a look to this other topic https://www.autoitscript.com/forum/topic/206464-regex-to-prepend-0x-to-string-chunks Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... 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