InputHook sees multiple press/release events for single press of NumLock

Report problems with documented functionality
User avatar
evilC
Posts: 4787
Joined: 27 Feb 2014, 12:30

InputHook sees multiple press/release events for single press of NumLock

Post by evilC » 15 Dec 2019, 16:20

Code: Select all

#SingleInstance force

Sleep 100 ; When hitting F5 to run script in SciTE, release of F5 appears in list. Suppress
ih := InputHook()
ih.KeyOpt("{All}", "SN")
ih.OnKeyDown := Func("AhkKeyEvent").Bind(1)
ih.OnKeyUp := Func("AhkKeyEvent").Bind(0)
ih.Start()

Gui, Add, ListView, h200, Key Name|SC|State
LV_ModifyCol(1, 100)
LV_ModifyCol(2, 50)
LV_ModifyCol(3, 50)
Gui, Show
return

AhkKeyEvent(state, ih, vk, sc){
	row := LV_Add(, GetKeyName("SC" DecToHex(sc)), sc, state)
	LV_Modify(row, "Vis")
}

DecToHex(val){
	return Format("{:X}", val)
}

GuiClose:
	ExitApp
Pressing NumLock once, I get
Image

lexikos
Posts: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: InputHook sees multiple press/release events for single press of NumLock

Post by lexikos » 21 Feb 2020, 17:15

When the hook suppresses NumLock, it generates extra events to ensure the NumLock state does not change.
// This handles the troublesome Numlock key, which on some (most/all?) keyboards
// will change state independent of the keyboard's indicator light even if its
// keydown and up events are suppressed.
You may use the "I1" InputHook option to ignore simulated input, or remove the "S" key option.

Post Reply

Return to “Bug Reports”