AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[GetKeyState Tool] KeyStateMonitor 1.0

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Tester



Joined: 06 Jul 2006
Posts: 48
Location: Poland

PostPosted: Sat Jul 08, 2006 9:00 pm    Post subject: [GetKeyState Tool] KeyStateMonitor 1.0 Reply with quote

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)


Last edited by Tester on Sun Jul 09, 2006 12:26 am; edited 2 times in total
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4710
Location: Boulder, CO

PostPosted: Sat Jul 08, 2006 11:42 pm    Post subject: Reply with quote

Nice! If you add "Sleep 100" or similar to the beginning of the Loop, the window looks more stable and the script does not use as much processor time.
Back to top
View user's profile Send private message
Cerberus™
Guest





PostPosted: Fri Jun 18, 2010 7:17 pm    Post subject: Reply with quote

Really cool script, thank you for making the easiest key press monitor I have been able to find on the net! And the distinction between logical and physical is also great.
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group