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 

"sticking" hotkeys demonstration script

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
vith
Guest





PostPosted: Sun Mar 02, 2008 9:40 pm    Post subject: "sticking" hotkeys demonstration script Reply with quote

I've been having hotkeys stick with a script of mine for a long time, so I decided to reduce it to the very basics. Chris maybe you can try this out and experience the issue yourself. This is AutoHotkey v1.0.47.05 on Windows XP.

Run the script and open a text editor.
Press [D] to start (and stop) the character sending.
Hold [F] and observe that when the key is physically held, the first counter increments.
Tap [F] at a steady pace until you notice the script miss a release event.
Observe that the counter is not incrementing as it did before when you were physically holding the key.
You'll also notice that if you have sending disabled, events aren't missed. You can reset the counters with [G].

Code:
#NoEnv
SendMode Input
#SingleInstance force
#Persistent
#InstallKeybdHook
SetTimer, Spam, 50
SendingEnabled := False
PressedCount := 0
ReleasedCount := 0

Spam:
  if (SendingEnabled)
  {
    Send, % (GetKeyState( "F", "p" ) ? "-" : "_" )
  }
  ToolTip, % PressedCount " " ReleasedCount " " PressedCount - ReleasedCount " " (GetKeyState( "F", "p" ) ? "pressed" : "released" )
return

*$D::SendingEnabled := !SendingEnabled
*$F::PressedCount := PressedCount + 1
*$F Up::ReleasedCount := ReleasedCount + 1
*$G::
  PressedCount := 0
  ReleasedCount := 0
return
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10450

PostPosted: Mon Mar 03, 2008 1:23 am    Post subject: Reply with quote

Although I couldn't get it to miss any of 500 events (even while it was sending), I believe you that it happens on some systems like yours. Perhaps it has to do with keyboard driver, system load, or some conflict with other software that's installed.

In any case, I'm not sure what can be done to fix it because the program relies on the OS for notification of keystrokes. If you haven't already, you could try raising the priority of your script via Process, Priority,, High If that doesn't help, a possible workaround is to use GetKeyState (perhaps via a timer) to check whether certain keys are in the wrong state and adjust accordingly (even restarting the script, if necessary).
Back to top
View user's profile Send private message Send e-mail
vith
Guest





PostPosted: Mon Mar 03, 2008 2:06 am    Post subject: Reply with quote

It's random of course, but it gets stuck for me on average every 75 events I'd guess. Seems like the faster the timer, the more missed events occur. It really seems like it only misses events if they coincide exactly with a Send. I'm using a dual core Athlon64, but I have the driver for it installed which syncs the TSC registers between cores. I'm using a SysInternals keyboard filter driver (Ctrl2Cap). And system load doesn't seem to matter. Happens with and without WoW running.

As you can see in the script, GetKeyState is the meat of it; the event handlers always fail at the same time as GetKeyState. Does GetKeyState make a system call every time, or is it just looking up the key state based on the events AHK has seen (and is missing)?

I think i'll be fine if I detect the (lack of) autorepeat though.
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10450

PostPosted: Fri Mar 07, 2008 3:18 pm    Post subject: Reply with quote

GetKeyState() makes a system call every time unless you specify the "P" flag, which retrieves the state AutoHotkey's keyboard/mouse hook thinks the button or key is physically in. More info:
Quote:
Under Windows NT/2000/XP or later, the physical state of a key or mouse button will usually be the same as the logical state unless the keyboard and/or mouse hooks are installed, in which case it will accurately reflect whether or not the user is physically holding down the key or button (as long as it was pressed down while the script was running). You can determine if your script is using the hooks via the KeyHistory command or menu item. You can force the hooks to be installed by adding the #InstallKeybdHook and/or #InstallMouseHook directives to the script.
Back to top
View user's profile Send private message Send e-mail
tsomzing



Joined: 12 Mar 2008
Posts: 1

PostPosted: Wed Mar 12, 2008 12:10 am    Post subject: Reply with quote

I'm having a similar problem, only it's far more pronounced than what Vith is seeing... I get the upkey event missed something closer to 1 in 10 times, even when turning the autohotkey process's priority to above normal.

It's possible that this is because I'm using an Ergodex and a g15 simultaneously with autohotkey, and both programs are running their own internal macro detection programs and drivers.

Perhaps one of these drivers catches the key up event and handles it internally, causing the OS to somehow miss the event having occurred?

It does seem odd that Autohotkey responds correctly to the key down state, and then later the key up state a large percentage of the time. I'm guessing the Ergodex must be responsible for somehow incorrectly notifying the os that the key is up?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports 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