Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Hotkeys interfering with mouse movement, and beeping


  • Please log in to reply
1 reply to this topic
Jaegan
  • Members
  • 21 posts
  • Last active: May 19 2008 11:02 PM
  • Joined: 12 Jul 2006
While doing some scripting I ran into a couple of strange errors, mostly relating to mouse movement.

1. The idea behind this script is to hold down the right mouse button, and have this simulate the continous pressing of the left mouse button.

Process, priority, , High  ; Have the script set itself to high priority
#InstallMouseHook
#SingleInstance force
#InstallKeybdHook
#UseHook On
SetBatchLines 10ms
#HotString SP
#MaxThreads 20
CoordMode, mouse, Screen
SetKeyDelay, 10, 0, Play
SetMouseDelay, 10 , Play

*Rbutton::
{
loop
   {
   getkeystate, state, RButton, P
   If state = U
      Break
   send, {LButton}
      Sleep, 10     
      }
} 

However, when the right key is depressed, it slows the movement of the mouse. To test this, move the cursor to the far left side of your screen and move your mouse to the far left of your mousepad. Depress the right mouse button, and drag the cursor to the right edge of the screen. Release the right mouse button, and move the cursor the left side of the screen. You will notice that your cursor reached the end of the screen before your mouse returned to the left edge of the mouse pad.

It seems that the frequency of the left click determines how much the mouse movement is delayed. With a sleep of 100, the delay is barely noticeable. With a delay of 10, it appears to slow the mouse movement rate by 15-20%.

Another odd note is that adding an additional item to the keystate up slows down the movement even more. Adding a [Shift Up] before the break makes a noticeable difference in the overall speed.

2. The idea behind this script to hold down Capslock to have it emulate the pressing of Control and Shift. This script also faced the same problem stated above.

Process, priority, , High  ; Have the script set itself to high priority
#InstallMouseHook
#SingleInstance force
#InstallKeybdHook
#UseHook On
SetBatchLines 10ms
#HotString SP
#MaxThreads 20
CoordMode, mouse, Screen
SetKeyDelay, 10, 0, Play
SetMouseDelay, 10 , Play
*Capslock::SendPlay, {LControl Down}{LShift Down}
*Capslock Up::SendPlay, {LControl Up}{LShift Up}

This also caused some system delay and temporary inability to press other keys. Changing it to Send stopped this latter problem, but not the mouse delay.

3. Finally, with regards to the above script, (after being changed to Send,) I received a strange beeping sound while using it. This occured when the capslock key was depressed, as well as W, E, and F. In addition, the W key would not fire while Capslock and E were depressed.

I was unable to eliminate the first two problems, and I believe that continuously firing a script might be resulting in a mouse delay. It seems this only applies to scripts that have both an Up and Down modifier. In the above script I also have the line

Lwin:Lctrl

Holding down Lwin caused no delay whatsoever.

As for the last problem, I have no clue what the source could be. If you have any suggestions on how to fix these problems, please let me know.

-Jaegan

Chris
  • Administrators
  • 10727 posts
  • Last active: Sep 14 2014 06:10 PM
  • Joined: 02 Mar 2004
I've reviewed your examples and tried the first one. I can see that the mouse seems to slow down slightly while frequent left-clicks are being sent.

However, I don't see anything obvious in the AutoHotkey code that might explain this (AutoHotkey simply calls the WinAPI to send keystrokes and mouse clicks; nothing fancy). Perhaps the mouse hook slows down the mouse during heavy clicking; but even if so, the only way to avoid it would be to avoid the mouse hook, which would defeat the purpose of your script (though maybe you could poll the mouse via GetKeyState to avoid using the mouse hook).

As for the other problems, I think they are probably just due to OS limitations with regard to keyboard and mouse handling. After all, the OS is designed and optimized to handle human input, not artificial input that overlaps fast clicking and keystrokes.

Also, don't forget that whenever you hold down a key on the keyboard, it begins to auto-repeat. These repeated keystrokes can interfere with artificial keystrokes being sent by the Send command. They might also interfere with mouse clicking. And as far as I know, the only way to stop a key from auto-repeating is to physically press some other key (the Send command is not enough).