taurus905 Posted October 6, 2023 Share Posted October 6, 2023 Hello, I'm writing a HotKey Manager which would allow a user to build there own HotKey by selecting one key at a time using their keyboard, such as, Ctrl + Shift + Win + p (by pressing "Ctrl" then "Shift" then "Win" then "p" The problem is, when the Win key is selected, the Start Menu pops up. I appreciate any ideas on how to prevent this from happening. Thank you. taurus905 "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs Link to comment Share on other sites More sharing options...
ioa747 Posted October 6, 2023 Share Posted October 6, 2023 46 minutes ago, taurus905 said: by pressing "Ctrl" then "Shift" then "Win" then "p" Take a look in help book The following hotkeys cannot be set: Alt, Ctrl, Shift, Win These are the modifier keys themselves! I know that I know nothing Link to comment Share on other sites More sharing options...
taurus905 Posted October 6, 2023 Author Share Posted October 6, 2023 This may illustrate my point more clearly than my words: HotKeySet("^+#p", _Was_Pressed) ; Ctrl + Shift + Win + p HotKeySet("{ESC}", _Exit) While 1 Sleep(10) WEnd Exit Func _Was_Pressed() ToolTip("Ctrl + Shift + Win + p", Default, Default, "Was Pressed") Sleep(2000) ToolTip("") EndFunc Func _Exit() Exit EndFunc Run this script and press "Ctrl + Shift + Win + p" taurus905 "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs Link to comment Share on other sites More sharing options...
paw Posted October 6, 2023 Share Posted October 6, 2023 look at https://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_SetWindowsHookEx.htm return 1 from the _KeyProc() callback function to "consume" the key and prevent it from being passed to programs (and make sure your code is correct 😛 ) some useful links SetWindowsHookExW LowLevelKeyboardProc Link to comment Share on other sites More sharing options...
Andreik Posted October 6, 2023 Share Posted October 6, 2023 (edited) If you press anything any other key before Win key the Start Menu don't pop up. Anyway you can use a keyboard hook to prevent the system from passing the message to the rest of the hook chain and you can process the key by your own will. Here is an example. #include <WinAPIConstants.au3> #include <StructureConstants.au3> #include <WinAPISys.au3> #include <WindowsConstants.au3> Global $Exit = False Global $hProc = DllCallbackRegister("KeyboardProc", "long", "int;wparam;lparam") Global $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hProc), _WinAPI_GetModuleHandle(0)) Do Sleep(10) Until $Exit _WinAPI_UnhookWindowsHookEx($hHook) DllCallbackFree($hProc) Func KeyboardProc($nCode, $wParam, $lParam) Local $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam) If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndIf If $wParam = $WM_KEYDOWN Then Local $vkCode = DllStructGetData($tKEYHOOKS, "vkCode") Local $flags = DllStructGetData($tKEYHOOKS, "flags") ConsoleWrite($vkCode & @CRLF) If $vkCode = 27 Then $Exit = True If $vkCode = 91 Then ;~ ProcessYourWinKey() Return 1 EndIf EndIf Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndFunc Edited October 6, 2023 by Andreik taurus905 1 When the words fail... music speaks. Link to comment Share on other sites More sharing options...
willichan Posted October 6, 2023 Share Posted October 6, 2023 Changing how the windows key functions could potentially interfere with how the user works with other apps outside of yours. Many apps I use that allow hotkeys to be defined use checkboxes for selecting modifier keys. If you aren't going to capture the full combo at once, you might think about using checkboxes instead. My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash Link to comment Share on other sites More sharing options...
Andreik Posted October 6, 2023 Share Posted October 6, 2023 I suppose he thought to register a hook just before he is about to receive the hotkey combo and disable after. Something like when a certain input it's focused then install the hook and when the input lost it's focus then uninstall the hook. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
taurus905 Posted October 7, 2023 Author Share Posted October 7, 2023 Thank you @paw @Andreik @willichan All great input. I truly appreciate your contributions to solving my issue. Since last night, I've considered a few options, including checkboxes instead of key presses or even just one checkbox for the Win key. I even thought about not using the Win key at all. But I like having four modifier keys, as opposed to three. As it stands, the Win key will need to be pressed once to record the key and show the Start Menu and again to hide the Start Menu. It's not as perfect as I wanted, but it's simple. Thanks for all the brain-storming and a great hook example from @Andreik which I will keep for future reference. taurus905 "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs 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