Mapping 2 different results to the same key - autohotkey

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

Related

Bind to key release without repeat

SC039::Send {LShift down}
SC039 Up::
Send, {LShift up}
Send, {Space}
Return
I expect this to do the following: when pressing the spacebar, it acts like the shift key. When I release it, I get one space bar press. Unfortunately, when I stay on the space bar, I get a bunch of spaces even though the key is never released. How can this expected behavior be implemented?
You need the * modifier(docs) so the hotkey is recongnized even if extra modifiers are held down (Shift)
Also, why are you using using the scancode?
*Space::SendInput, {LShift Down}
*Space Up::SendInput, {LShift Up}{Space}
Check dual-key "SpaceFN" keyboard layout https://github.com/lydell/spacefn-win
Probably this is what you are looking for or even more.

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

Can AutoHotKey intercept a mouse click?

aI use AutoHotKey to remap a few keys, and that has been extremely useful. Example:
!t::
Send, ^t
return
That would intercept Alt-t key and send Ctrl-t instead.
I was wondering if there's a way to intercept an Alt-LeftMouseClick and send Ctrl-LeftMouseClick instead?
This maps ALT+LeftMouseClick to Ctrl+LeftMouseClick
!lbutton::send ^{click}
Turns out, I could do it with:
!LButton::
Send, {Control down}
MouseClick
Send, {Control up}
return

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

Sending and releasing multiple keys at once using AutoHotkey

I'm attempting to send three keys (Alt, Shift, Q) at same time using this script:
:*:pk:: ;
Send, {AltDown}{ShiftDown}{qDown}
return
When I run this is it does not release the keys, it seems like the Alt button remains pressed. After the above keys are pressed I then want to press the "q" character again (separately, not at same time).
How can I amend my script above to achieve this?
When using Down, you must also send an Up to the same key or else it will remain pressed. This can be achieved like this:
:*:pk::
Send, {Alt Down}{Shift Down}{q Down}{Alt Up}{Shift Up}{q Up}
Send, {q}