Hi folks,
Is there a more lightweight way of checking if Ctrl/Shift/Alt buttons are pressed than GetKeyState()?
I have keys get stuck sometimes on my old PC, and since many keys need to be constantly monitored, I wonder if there is a more lightweight / non-intrusive way to check them.
Thanks!
Lightweight alternative to GetKeyState()?
Re: Lightweight alternative to GetKeyState()?
Declare a pass-through hotkey to all modifier buttons?
Code: Select all
~Shift::
~Ctrl::
~Alt::
~LWin::
~RWin::
tooltip % "Modifier pressed: " A_ThisHotkey
return
~Shift up::
~Ctrl up::
~Alt up::
~LWin up::
~RWin up::
tooltip % "Modifier released: " A_ThisHotkey
return
Re: Lightweight alternative to GetKeyState()?
evilC, thanks!
Yeah, that' a good idea. I will just add SetTimer to wait few seconds before showing tooltip
Yeah, that' a good idea. I will just add SetTimer to wait few seconds before showing tooltip
Re: Lightweight alternative to GetKeyState()?
A bit more elegant code - routes all hotkeys through same function, but instead of having to do string manipulation to work out what modifier was pressed / released (A_ThisHotkey would give like "~*Shift up" instead of "Shift"), it is all pre-calculated
Code: Select all
#SingleInstance Force
mods := ["Shift", "Ctrl", "Alt", "LWin", "RWin"]
for i, mod in mods {
fn := Func("ModifierEvent").Bind(mod, 1)
hotkey, % "~*" mod, % fn
fn := Func("ModifierEvent").Bind(mod, 0)
hotkey, % "~*" mod " up", % fn
}
ModifierEvent(key, state){
Tooltip % "Modifier " key " entered state " state
}
Re: Lightweight alternative to GetKeyState()?
evilC, thanks!
Who is online
Users browsing this forum: Google [Bot], just me and 292 guests