XButton2 as a modifier

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Flowgun
Posts: 74
Joined: 25 Aug 2022, 09:42

XButton2 as a modifier

Post by Flowgun » 04 Oct 2022, 09:28

Hello everyone,
so I wanted to map WASD to arrow keys when I'm holding XButton2 on the mouse.
the code below works great with modifiers ("Holding XButton2 + Ctrl + left" sends "Ctrl+Left"), but it stops XButton2 from working normally:

Code: Select all

XButton2 & w:: send, {up}
XButton2 & a:: send, {Left}
XButton2 & s:: send, {Down}
XButton2 & d:: send, {Right}
XButton2 & e:: send, {PgUp}
XButton2 & q:: send, {PgDn}

When I add a tilde symbol before the hotkeys like the code below, XButton2 keeps on working normally, but holding modifiers does nothing:

Code: Select all

~XButton2 & w:: send, {up}
~XButton2 & a:: send, {Left}
~XButton2 & s:: send, {Down}
~XButton2 & d:: send, {Right}
~XButton2 & e:: send, {PgUp}
~XButton2 & q:: send, {PgDn}

I tried this, but modifiers still don't work:
~XButton2 & w::
if getkeystate("ctrl","P")
{
if getkeystate("Shift","P")
{
send, ^+{up}
}
else
send, ^{up}
}
else if getkeystate("Shift","P")
send, +{Up}
else
send, {up}
return

Any thoughts?

Flowgun
Posts: 74
Joined: 25 Aug 2022, 09:42

Re: XButton2 as a modifier

Post by Flowgun » 04 Oct 2022, 09:51

P.S: I made a mistake. This is the code that keeps the modifiers working (no "send,"):

Code: Select all

XButton2 & w::up
XButton2 & a::Left
XButton2 & s::Down
XButton2 & d::Right

User avatar
mikeyww
Posts: 26435
Joined: 09 Sep 2014, 18:38

Re: XButton2 as a modifier

Post by mikeyww » 04 Oct 2022, 10:26

See https://www.autohotkey.com/docs/Hotkeys.htm#combo.
The prefix key loses its native function: In the above example, Numpad0 becomes a prefix key; but this also causes Numpad0 to lose its original/native function when it is pressed by itself. To avoid this, a script may configure Numpad0 to perform a new action

Code: Select all

XButton2::XButton2
XButton2 & w::Up

Post Reply

Return to “Ask for Help (v1)”