Autohotkey Click and hold RMB+W macro - mouse

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

Related

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

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

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

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...

Conditionally intercept a mouse click in Autohotkey?

I want to have a script which will intercept a mouse click and send a key press instead, but only when the capslock key is toggled on. I want the mouse click to be sent normally if the capslock key is toggled off.
Currently I have made this:
$LButton::
if GetKeyState("CapsLock", "T") = 1
send, {a}
else
send, {LButton}
return
The problem with this is that when the capslock key is off, the left button can click perfectly normally but it cannot drag.
If I change $ to ~, it is able to drag but it also performs a click when the capslock key is toggled on.
Is there any way to make the script ignore the click completely if the capslock key is toggled off?
AHK_L's #If will give you what you want:
#If GetKeyState("CapsLock", "T")
LButton::Send, a
With this code, you won't have to bother what happens when capslock is off. AHK will intercept the click on a lower level and let it trickle through.
How to use the symbol UP.
SetBatchLines, -1 ; you pretty much have to include this to speed up the execution
LButton::
if( GetKeyState("CapsLock", "T") )
tooltip, ignore left click
else
send, {LButton Down}
return
LButton UP::
send, {LButton Up}
return

script to use Left Click as Left Shift does not work correctly

I've search AHK forums but couldn't solution.
The script I found on AHK to use LShift as LButton does not work correctly..when press & hold left shift and move the mouse pointer, it can't copy text exactly like as if click and hold left mouse. What I mean by exactly is.. press & hold left shift and move the mouse pointer copies the whole paragraph or section of text..not just the few words I wanted.
My first time here & newbie w/ AHK. Your time is appreciated.
~Lshift::
Send {LButton}
return
F10::exitapp
you could try:
~Lshift::
Send {LButton Down} ; Press the LButton key Down
KeyWait, LShift ; Wait for the LShift key to be lifted
Send {LButton Up} ; Release the LButton key
return
F10::exitapp