Recently I try to simulate some custom mouse chords in in-house graphical software. Because I have many problems with this I make some little script to report pressed keys. It is handy in case when few key/mouse presses are simulated by other hotkey with DOWN/UP pairs or custom chords hotkey definitions.
Description:
This script continuously reports logically and physically pressed keys. This is kind of realtime addition to "Key History" window of AKH.
Screenshot:
Usage:
Use this by saving script code in KeyStateMonitor.ahk file and add following line to your script
Code:
#Include *i KeyStateMonitor.ahk
By default you can run this script by Win+F3 hotkey (you can change this to own hotkey in first line of the following code).
If you want change default monitored keys then change
ksm_monitor_keys variable. If you want to change default window title then edit
ksm_caption variable.
Script code:Code:
#F3::
ksm_caption = KeyState Monitor 1.0
ksm_monitor_keys := "O Z LButton RButton MButton Space"
ksm_dialog_closed := 0
Gui, Font, bold cRed
Gui, Add, Text, x16 y17 w110 h20, Logically pressed:
Gui, Font, norm
Gui, Add, Text, x136 y17 w330 h20 vsLState,
Gui, Font, cBlack
Gui, Add, Text, x16 y47 w110 h20, Physically pressed:
Gui, Add, Text, x136 y47 w330 h20 vsPState,
Gui, Add, Button, x6 y187 w450 h180, %A_Space% Set focus for this button`n`n(test key/mouse presses over this button)
Gui, Add, Text, x16 y87 w110 h20, Title for this window:
Gui, Add, Edit, x136 y87 w320 h20 gChangeCaption vksm_caption,
Gui, Add, Text, x16 y117 w110 h20, Monitored keys:
Gui, Add, Edit, x136 y117 w320 h20 gChangeKeys vksm_monitor_keys, %ksm_monitor_keys%
Gui, Add, Checkbox, x16 y147 w110 h20 gToggleTooltip vksm_tooltip,display tooltip
Gui, Add, Text, x316 y167 w140 h20 Disabled,KeyState Monitor 1.0 by Jav!
Gui, Show, x417 y436 h374 w469, %ksm_caption%
ksm_this_winID:=WinActive(ksm_caption)
StringSplit, ksm_keys_array, ksm_monitor_keys, %A_Space%%A_Tab%,,
loop {
Sleep 20
loop %ksm_keys_array0% {
ksm_key_now:=ksm_keys_array%A_Index%
if (GetKeyState(ksm_key_now)) {
if not (InStr(sLState, " " . ksm_key_now . " "))
sLState:=sLState . " " . ksm_key_now . " "
}
else
StringReplace, sLState, sLState, %A_Space%%ksm_key_now%%A_Space%,, All
if (GetKeyState(ksm_key_now, "P")) {
if not (InStr(sPState, " " . ksm_key_now . " "))
sPState:=sPState . " " . ksm_key_now . " "
}
else
StringReplace, sPState, sPState, %A_Space%%ksm_key_now%%A_Space%,, All
}
if ksm_tooltip
Tooltip, Logical: %sLState%`nPhysical: %sPState%
GuiControl, ,sLState,%sLState%
GuiControl, ,sPState,%sPState%
if ksm_dialog_closed
break
}
Return
GuiClose:
Gui, Destroy
ksm_dialog_closed:=1
if ksm_tooltip
Tooltip,
return
ChangeCaption:
GuiControlGet, ksm_caption
WinSetTitle, ahk_id %ksm_this_winID%,, %ksm_caption%
return
ToggleTooltip:
GuiControlGet, ksm_tooltip
Tooltip,
return
ChangeKeys:
GuiControlGet, ksm_monitor_keys
StringSplit, ksm_keys_array, ksm_monitor_keys, %A_Space%%A_Tab%,,
return
If anyone have some suggestions or comments about above code, feel free to post it here.
Regards,
Jav!
updates:
- sleep at beginning of loop (thanks Laszlo)