InputHook() will not recognize already defined Win+Key hotkeys

Report problems with documented functionality
WalterRoberts
Posts: 67
Joined: 25 Feb 2020, 20:00

InputHook() will not recognize already defined Win+Key hotkeys

Post by WalterRoberts » 03 Jun 2021, 13:45

For some reason InputHook() will not recognize Win+Key hotkeys which are already defined somewhere else in the script. All other modifier combinations will still be recognized even when defined elsewhere.

Code: Select all

	GetKeyboardInput(SpecificModifiers:=false) {
		ih := InputHook()
		ih.KeyOpt("{All}", "ES") ;End Keys & Suppress
		ih.KeyOpt("{LCtrl}{RCtrl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}", "-ES") ;Exclude the modifiers
		ih.Start()
		ih.Wait()
		if SpecificModifiers
			Return KeyboardInput := ih.EndMods . ih.EndKey
		NeutralModifiers := RegExReplace(ih.EndMods, "[<>](.)(?:>\1)?", "$1")
		Return KeyboardInput := NeutralModifiers . ih.EndKey
	}

#q::
	KeyboardInput := GetKeyboardInput()
	if (KeyboardInput = "Escape")
		Exit
	else if (KeyboardInput = "t")
		MsgBox, t
	else if (KeyboardInput = "^t")
		MsgBox, ^t
	else if (KeyboardInput = "!t")
		MsgBox, !t
	else if (KeyboardInput = "+t")
		MsgBox, +t
	else if (KeyboardInput = "#t")
		MsgBox, "Not working if hotkey is already defined"
	else if (KeyboardInput = "^#t")
		MsgBox, ^#t
	return

t::MsgBox, 1
^t::MsgBox, 2
!t::MsgBox, 3
+t::MsgBox, 4
#t::MsgBox, 5
^#t::MsgBox, 6

lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: InputHook() will not recognize already defined Win+Key hotkeys

Post by lexikos » 04 Jun 2021, 23:47

Add #UseHook or #If condition or use ListHotkeys, and you will see that all of the keyboard-hook hotkeys take precedence over InputHook. This is not a bug, just not well documented. See How to Prevent #HotIf Hotkeys from Affecting InputHook.

#t and #q are standard system hotkeys on Windows 10, and therefore require the keyboard hook. All of the other hotkeys can usually use the reg method, because they have not been already registered by some other process.

WalterRoberts
Posts: 67
Joined: 25 Feb 2020, 20:00

Re: InputHook() will not recognize already defined Win+Key hotkeys

Post by WalterRoberts » 07 Jun 2021, 18:22

Okay thank you for clarifying the case. Could be useful to have an option/flag to force InputHook to take precedence over k-hooks in order to guarantee the expected Input. I have read that you ran into complications trying to implement this, which is unfortunate, but it's not that important anyway, it would just come in handy under certain circumstances.

Post Reply

Return to “Bug Reports”