windowsmouseeventautohotkeyahk2

Switching chrome tabs not working correctly in Auto hot key


In the ahk script, i have created an action to change tabs by clicking the Xbutton1(back button) of my mouse with the scroll of the mouse. So when i press xbutton1 and scroll up or down the tabs in chrome change accordingly.

However, the issue I'm facing is, after switching the tab with xbutton1 and wheel scroll, when i release the xbutton1, its default action of going back is performed as well. how do i modify the script such that after switching the tabs and releasing xbutton1 the tab does not go back.

Also i don't want to permanently disable the going back feature of xbutton1, please help me, I'm new to ahk scripting, i don't know what to do here.

~XButton1 & WheelUp::
    Send, ^{PgUp}
    return

~XButton1 & WheelDown::
    Send, ^{PgDn}
    return

Solution

  • The tilde prefix (~) prevents AHK from blocking the XButton1 key-down/up events. It allows the key event to pass through.

    If you remove ~, XButton1 loses its original function. To avoid this, make the key to send itself:

    XButton1 & WheelUp::Send, ^{PgUp}
    
    XButton1 & WheelDown::Send, ^{PgDn}
    
    XButton1::Send, {XButton1}