Alt + mouse wheel sometimes sends key bound to regular mouse wheel Topic is solved

Ask gaming related questions (AHK v1.1 and older)
Tiagolop
Posts: 2
Joined: 27 Sep 2021, 18:42

Alt + mouse wheel sometimes sends key bound to regular mouse wheel

27 Sep 2021, 19:24

I'm using ahk on a game that doesn't allow you to bind mouse wheel up/down so I set - and = to mwu and mwd respectively. I want it to send -/= when I press mwu/mwd, alt- or alt= when I press alt mwu or alt mwd, shift- or shift= when I press shift mwu or shift mwd. I also want ctrl mwu/ mwd to just behave like regular mwu/mwd

The unmodified, ctrl and shift ones work perfectly, but with the alt modifier it sometimes sends a regular - or = in the mix when I'm rolling the scroll wheel fast, especially if I quickly switch from rolling it down to rolling it up (or vice-versa) and, more rarely, it might also send a regular mouse scroll. I read it could be sending keystrokes faster than what ahk can handle and some were "getting through" but that doesn' happen at all when using shift mwu/ mwd.

Here's what I'm using

Code: Select all

WheelUp::
Send {-}
Return
WheelDown::
Send {=}
Return

^WheelUp::
MouseClick,WheelUp
Return
^WheelDown::
MouseClick,WheelDown
Return

+WheelUp::
Send +{-}
Return
+WheelDown::
Send +{=}
Return

!WheelUp::
Send !{-}
Return
!WheelDown::
Send !{=}
Return
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Alt + mouse wheel sometimes sends key bound to regular mouse wheel  Topic is solved

27 Sep 2021, 20:36

Code: Select all

WheelUp::
+WheelUp::
!WheelUp::Send {Blind}-
WheelDown::
+WheelDown::
!WheelDown::Send {Blind}=
^WheelUp::Send {WheelUp}
^WheelDown::Send {WheelDown}
Tiagolop
Posts: 2
Joined: 27 Sep 2021, 18:42

Re: Alt + mouse wheel sometimes sends key bound to regular mouse wheel

28 Sep 2021, 15:01

@mikeyww
Thank you so much, this works perfectly !
I'm quite new to using ahk and hope to someday learn enough to make my scripts neat like that.
Do you happen to know what in the original script was causing the regular - and = to slip through ?


Edit:
I just noticed something else: If I'm using a modifier key while using the mousewheel and let go of the modifier key while scrolling the modifier key will become "stuck" and using the scroll by itself will continue to trigger it as if the modifier was held down. I have to then stop scrolling and press the modifier key again to "unstick" it.
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Alt + mouse wheel sometimes sends key bound to regular mouse wheel

28 Sep 2021, 15:19

I am glad to hear it. Your script had the right idea. I did reproduce the problem that you experienced. My hunch is that, as AHK was rapidly managing all of the Shift up & down sequences with every scroll of the wheel-- and doing it multiple times in quick succession-- there are some imperfections there at times, in what the system is able to handle, and how quickly. If you look at the KeyHistory, it may shed light on this in some instances. This may not be an AHK issue as much as a system issue, though I am uncertain (others here know more). In some cases, using SendInput or text mode can "improve reliability", though this term is a bit vague. The documentation contains some explanations about how they may help reliability or avoid interruptions in sequences. I do not recall whether I tried SendInput with your script. The wheel is perhaps unique in that it can generate such a large number of manually triggered events very quickly; this may have created some of the challenge with the intermingled Shift sequences. Thus, one or two "clicks" of the wheel are not a problem, but 10 or 20 via one prolonged spin might yield the problem. That's just a guess, as I did not study the issue very carefully.

The issue of the "stuck modifier" is well known and reported by multiple users. It is said to be caused by conflicting software. Again in your case, this issue may be exacerbated by use of the wheel in some way. In some instances, sending the modifier key up (e.g., Send {Shift up}) at some point might help. I successfully use that approach myself, but it does not seem to work in all situations. I have never discovered what software on my system conflicts with AHK, so I just deal with the occasional issues by having a "KBreset" script that does these things upon triggering a hotkey.

In terms of "neat":
1. If your hotkey subroutine has one command, or something that can be written on one line, you can put it on the same line as the hotkey. It will have an implicit Return.
2. You can stack hotkeys as shown. Each hotkey in the stack will execute the routine at the bottom of the stack.
As your script shows, these techniques are not required. They mostly serve to condense the script. In some cases, they are a convenience that can avoid duplications in code and so also sometimes decrease the risk of a bug, or increase the ease of modifying the script.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 56 guests