Brett Parker
Brett Parker

Reputation: 1

AHK issue with mousewheel key remap

I am having trouble with my script, and I don't understand why its not working the way I want it to.

What I want: when I use my mouse wheel up, I want it to use my health flask, or send the keyboard '1 key' once, and when I use mouse wheel down, I want it to use my quicksilver flask (send the keyboard 'key 5' once), but what is happening, is it's repeating, so instead of using the flask once, it uses the whole flask, or rather it hits the keyboard key 1 or 5 several times, its auto repeating.

The question I have is: how can I stop it from repeating with the send command, since in the application, if I hold 1 or 5 it does not auto repeat, I have to click it again. So the send command is autorepeating, and I don't want it to.

I thought maybe it was because when I did the mousewheel down or up it was doing it multiple times, but when I set it to 1 in windows in mouse control panel, it did not help.

Here is my script, I thought it was simple...

#IfWinActive Path of Exile

WheelUp::Send {1}

WheelDown::Send {5}

Before I tried to use the send command, I tried to do it with this script:

#IfWinActive Path of Exile

WheelUp::1

WheelDown::5

And this script doesn't work at all, with the application... but it works outside of the the application if I don't use the #IfWinActive line.

Any help would be appreciated.

Upvotes: 0

Views: 3735

Answers (2)

Lexikos
Lexikos

Reputation: 1067

Your first script (below) sends exactly one key-down event followed immediately by one key-up event, for each notch of the mouse wheel. The keystroke is not repeated unless the mouse wheel is still moving (as reported by your mouse). The Send command does not autorepeat.

#IfWinActive Path of Exile
WheelUp::Send {1}
WheelDown::Send {5}

It's fairly common for games to not respond as reliably to Send as other applications, hence the FAQ Why do Hotstrings, Send, and Click have no effect in certain games?, which provides some possible solutions. For instance, I would suggest using SetKeyDelay's PressDuration parameter to increase the delay between "pressing" and "releasing" the key. Alternatively, you can use Send {1 down}, Sleep xxx and Send {1 up}.

You may want to add {Blind} to the front of each send, like Send {Blind}1, otherwise it may interfere with your use of modifier keys. For instance, if you are holding Ctrl, Send 1 will automatically "release" Ctrl, send 1, then "press" Ctrl back down.

If your mouse is causing the hotkey to trigger multiple times, Blauhirn's answer may work, but it can be simplified (with additions as described above):

SetKeyDelay 20, 20

#IfWinActive Path of Exile

WheelUp::
    Send {Blind}{1}
    Sleep 500  ; Wait 500ms
    return  ; WheelUp can't fire a second instance until the first returns.

WheelDown::
    Send {Blind}{5}
    Sleep 500
    return

The drawback of this simple method is that if you activate one hotkey and then the other hotkey before the first Sleep returns (i.e. within 500ms in this example), both will be blocked until the second Sleep finishes. Reducing the sleep time would help avoid this.

Your second script is invalid. That is, WheelUp::1 is invalid, as documented:

The following keys are not supported by the built-in remapping method:

  • The mouse wheel (WheelUp/Down/Left/Right).

The reason is that unlike other keys, the WheelUp/Down "pseudo-keys" can only be pressed, not released. So when you remap WheelUp::1, it maps WheelUp to {1 down} and never sends {1 up}; that is, it presses 1 but never releases it.

Upvotes: 0

phil294
phil294

Reputation: 10872

Assuming it is your mouse which triggers the hotkey multiple times, you may try the following (not tested):

hotkey, ifWinActive, Path of Exile
hotkey, WheelUp, send1, on
hotkey, WheelDown, send5, on
hotkey, ifWinActive
return

send1:
send 1
hotkey, WheelUp, send1, off ; prevents WheelUp to send 1 more than one time for 1000 ms
sleep, 1000
hotkey, ifWinActive, Path of Exile
hotkey, WheelUp, send1, on
hotkey, ifWinActive
return

send5:
send 5
hotkey, WheelDown, send5, off ; prevents WheelDown to send 5 more than one time for 1000 ms
sleep, 1000
hotkey, ifWinActive, Path of Exile
hotkey, WheelDown, send5, on
hotkey, ifWinActive
return

Upvotes: 0

Related Questions