Solution to AHK sending too many events when holding down a mouse button? - autohotkey

When using three different methods of holding down the left mouse button:
Mouseclick, left, 0, 0, 1, , D, R
or
Send {LButton down}
or
Click down
the game I'm making a macro for logs me out complaining that I'm sending too many actions. I tested this by itself as a script, like:
F3::
Click down
return
So there's no chance other code is causing it.
I was wondering if there are any settings I can use (by settings I mean like CoordMode, Mouse, Screen) or any other solution to perhaps prevent whatever rapid event sending AHK is using to simulate a mouse button being held down. Is there any possible fix I can try? I'm open to testing any ideas.

Well, you could introduce a Sleep like so:
LButton::
while (GetKeyState("LButton", "P"))
{
MouseClick, left
Sleep, 100
}
return
Though I personally dislike binding the mouse click to behaviours via the same mouse click, as it can lead to results that are difficult to get out of.
Here's an example with a toggleable hotkey.
Insert::
SendInput, {LButton Down}
loop
{
Sleep, 100
if getkeystate("Insert", "p") ; Hold for a second as the Sleep will delay recognition.
{
SendInput, {LButton Up}
break
}
}
return
Edited per the comments:
Insert::
SendInput, {LButton Down}
KeyWait, Insert, D
SendInput, {LButton Up}
return

Related

LButton Hotkey seems to prevent Send, {LButton}

I'm at a loss here. As soon as I add the LButton hotkey, the Send, {LButton} doesn't seem to work, but they show up in recently executed lines.
Env. Windows 7x64, Disabled Touchpad, AHK v1.1.31.01.
I try to emulate the Wink application (from DebugMode) to capture screenshots for training purposes. For that reason, I want to capture a screenshot just before a mouse click. This looks easy, and I even vaguely remember doing similar mouse hotkeys in the past. However I can't get this to work.
Step 1: I just reduced it to this simple script:
#InstallKeybdHook
#InstallMouseHook
#UseHook
#Persistent
Return
a::
Send, {LButton}
Return
q::
ExitApp
When using this script, I can simulate clicking the Left Mouse Button through the a key. Nothing special.
However as soon as I add either a line with "Hotkey, $LButton, MySendClick", or "$LButton::" the previously working a hotkey no longer works. In the recently executed lines, you can see the "Send, {LButton}" lines, but nothing is being send. Unexpectedly, the a hotkey actually causes the "$LButton::" hotkey to trigger (without it sending {LButton}). When I change the a hotkey to send "RButton" and the $LButton:: to $RButton::, then Send {Click} works perfectly (eventhough the a hotkey should never be able to trigger $RButton::).
Originally I just wanted to have the following HotKey:
$LButton::
SoundBeep, 300, 150 ; For testing only
; Send, ^{PrintScreen} ; To trigger Greenshot in the background
Sleep, 100
Send, {LButton}
Return
I upgraded from AHK v1.1.22.04 to v1.1.31.01. No improvement.
I tried "Click", "sendInput, {LButton}", "Send {Click}", "MouseClick, Left".
I tried "$LButton::", "vk01sc000::", "Hotkey, $LButton, MyClick".
Is this an issue with my specific Windows 7 configuration or an "undocumented AHK feature"?
#InstallKeybdHook
#InstallMouseHook
#UseHook
#Persistent
Return
a::
Send, {LButton}
Return
$LButton::
SoundBeep, 300, 150 ; Should be Send, ^{PrintScreen} ; To trigger Greenshot in the background
MouseClick, Left
Return
q::
ExitApp
In this last test example, When $LButton:: is disabled, the a hotkey works like a charm, but as soon as I enable $LButton::, the a hotkey triggers $LButton:: and no mouse click is being sent to the windows applications.
I would appreciate it when other Windows 7 users could quickly test this issue.
In my experience, using keys that you still want the input to pass through need the Tilde prefix.
https://www.autohotkey.com/docs/Hotkeys.htm#Tilde
~LButton::
SoundBeep, 300, 150 ; Should be Send, ^{PrintScreen} ; To trigger Greenshot in the background
KeyWait, LButton ; Wait for lbutton to be released.
Return

Autohotkey Click and hold RMB+W macro

I'm trying to make a macro that clicks and holds "W" key and "RMB" when "RMB" is being held.
So far I've came up with something like this:
RButton::
if( not GetKeyState("RButton" , "P") )
Click, down, right
Send {w down}
return
RButton Up::
Click, up, right
Send {w up}
This only holds "W" key, but not "RMB".
I would appreciate some help.
RMB - Right mouse button

Press both mouse buttons when holding left click

When I hold down left mouse button I would like for the right mouse button be held down also.
The right mouse would then release when the left mouse is no longer being held. So both buttons can be controlled simultaneously with the left click.
LButton::RButton means Left Button acts like your Right Button. The ~ modifier means "Fire the hotkey as well as whatever it's remapped to".
~LButton::RButton
Quick edit: If you need it to activate after Left Button has been held for a certain amount of time, use this:
; Time for LButton to be held down before RButton is sent (in milliseconds)
waitTime := 500
return
~*LButton::
while GetKeyState("LButton", "P")
if (A_TimeSinceThisHotkey > waitTime){
Send, {RButton Down}
KeyWait, LButton
Send, {RButton Up}
}
return

Using Send doesn't always work in AutoHotKey?

I have a very simple script to try and remap my AppsKey (the one on the right hand side of the keyboard, between WinKey and Ctrl) to Shift + F2 for the Uplay overlay.
AppsKey::
Send, +{F2}
Return
As you can see, it's very basic, however, when I try to use it in-game (Far Cry 3 in this instance), it works erratically. Like sometimes when I press the AppsKey, the overlay opens. Sometimes it doesn't and I have to repeatedly tap the AppsKey for it to finally show up or close.
No, my AppsKey isn't broken. I tried mapping it to something else and it works without problems. I just want some lead as to why it's acting erratically in this case.
Per the comments, the solution should be akin to this:
AppsKey::
SendInput, {Shift down}{F2 down}
Sleep, 50
SendInput, {Shift up}{F2 up}
return

Mapping 2 different results to the same key

I'm kinda new at this. I have a mouse with only 3 keys that I'd like to write a script for to allow me to use the right mouse button like a "browser back" key if clicked, while still retaining the original function if held for a longer period of time.
RButton::
sleep 400
GetKeyState, state, RButton
if state = U
send {Browser_Back}
else
send {RButton}
keywait, RButton
return
Currently, all my script above does now is activates the "browser back" function, regardless of time held down. I think there's a problem with the key being repeated at the send {RButton} line, but adding a $ to RButton:: didn't seem to help (if it was supposed to, idk.) If I replace the 3 "RButton" instances (not including the one on the send line) with a key on the keyboard, it works perfectly though. Help would be appreciated. Thanks.
Adjusted the code from BlackHolyMan's response to fix it. In case anybody was curious or wanted it, here it is:
RButton::
KeyWait, RButton, U T0.5
If !ErrorLevel
{
send {Browser_Back}
return
}
else
{
send {RButton Down}
KeyWait, RButton
send {RButton up}
}
return
Hi this may be just about what you need
RButton::
KeyWait, RButton, U T0.5
If !ErrorLevel
send {Browser_Back}
else
{
send {RButton Down}
KeyWait, RButton
send {RButton up}
}
return
Still some things you may need to fix as i did not test it for long...