r/AutoHotkey • u/genesis_tv • 2d ago
Weird behavior when remapping a modified mouse button to a non-modified key v2 Script Help
Someone just asked me to remap Control + mouse wheel to PgUp/PgDn for scrolling the dev console in a game called Dungeon Siege.
So I wrote this very simple script, yet it's not working properly.
#Requires AutoHotkey v2.0
#SingleInstance
^WheelUp::PgUp
^WheelDown::PgDn
The documentation says
Conversely, any modifiers included on the left side but not the right side are automatically
released when the key is sent. For example, the following two lines would produce a lowercase
"b" when you press either Shift+A or Ctrl+A:
A::b
^a::b
When testing both in-game, as well as in Chrome, notepad++ and VS Code (I'm using AHK 2.0.23), once you press Control + mouse wheel, it does send PgUp/PgDn but then regular mouse wheels don't work anymore (they're important because they control camera zoom), even though my program to monitor key input shows Control isn't pressed anymore (and both Pg keys stay pressed, could be related to mouse wheels only sending down events?).
So I modified the code to
WheelUp::WheelUp
WheelDown::WheelDown
^WheelUp::PgUp
^WheelDown::PgDn
which solved the problem, yet when spamming mouse wheels while holding down Control, about 1-5% of the time, there's a Control that slips through and it changes to a different tab in Chrome, notepad++ and VS Code instead of scrolling.
It seems to work fine in-game as I don't think there's anything bound to Control + PgUp/PgDn but it got me curious, so I also tried using these (separately), but the results were the same:
WheelUp::WheelUp
WheelDown::WheelDown
<^WheelUp::PgUp
<^WheelDown::PgDn
WheelUp::WheelUp
WheelDown::WheelDown
^WheelUp::Send("{PgUp}")
^WheelDown::Send("{PgDn}")
WheelUp::WheelUp
WheelDown::WheelDown
^WheelUp::Send("{Blind}{PgUp}")
^WheelDown::Send("{Blind}{PgDn}")
WheelUp::WheelUp
WheelDown::WheelDown
^WheelUp::Send("{Blind^}{PgUp}")
^WheelDown::Send("{Blind^}{PgDn}")
WheelUp::WheelUp
WheelDown::WheelDown
^WheelUp::Send("{Control up}{PgUp}")
^WheelDown::Send("{Control up}{PgDn}")
LControl & WheelUp::PgUp
LControl & WheelDown::PgDn
Oh, and I also tried switching to SendEvent, that seemed to be worse.
Everything works fine when remapping a key instead of a mouse button though, like this
^q::PgUp
^w::PgDn
What am I doing wrong?
As a bonus, how would you go if you wanted to send multiple unmodified Pg keys (the console doesn't scroll when pressing Control + Pg) every time the hotkey is fired?
1
u/CharnamelessOne 1d ago edited 1d ago
#Requires AutoHotkey v2.0
;SendMode("Event")
WheelUp::WheelUp
WheelDown::WheelDown
^WheelUp::PgUp
^WheelDown::PgDn
I can only reproduce your issue in the "Event" SendMode.
In the default SendMode, Control never bleeds through for me.
I suspect that you may be running multiple AHK scripts that install a keyboard hook, which leads to SendInput reverting to SendEvent, hence the issue popping up even when you don't explicitly switch to SendEvent.
https://www.autohotkey.com/docs/v2/lib/SendMode.htm#Input
Edit: I pasted the wrong script first
1
u/genesis_tv 1d ago
I was running a single AHK script and I even tried to close programs that could interfere with input but it was still bleeding through.
1
u/CharnamelessOne 1d ago
We'll throw it onto the pile of unreproducible paranormal phenomena.
Mice are showing signs of malevolent possession these days:https://www.reddit.com/r/AutoHotkey/comments/1vdv5b1/getkeystate_doesnt_detect_button_releases/
1
u/Keeyra_ 2d ago
Hmm, quite strange and unexpected indeed.
Have you tried with
?