AutoHotkey Community

It is currently May 27th, 2012, 8:46 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: July 8th, 2006, 10:00 pm 
Offline

Joined: July 6th, 2006, 7:26 pm
Posts: 48
Location: Poland
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:
Image

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 July 9th, 2006, 1:26 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 9th, 2006, 12:42 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 18th, 2010, 8:17 pm 
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.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, tomoe_uehara, Xx7 and 9 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group