Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Chematronix/5d7e12f7e580652aac46dc8080906e4f to your computer and use it in GitHub Desktop.
Save Chematronix/5d7e12f7e580652aac46dc8080906e4f to your computer and use it in GitHub Desktop.
TabsOnWheels: Switch browser (or other program's) tabs with your mouse wheel when hovering over the tab bar (and optionally address bar). Press Middle/Wheel Mouse Click to switch tabs from anywhere in the program.
; ---------------------------------------------------- ;
; TabsOnWheels ;
; ---------------------------------------------------- ;
; Switch browser (or other program's) tabs with your mouse wheel when hovering over the tab bar (and optionally address bar).
; Press Middle/Wheel Mouse Click to switch tabs from anywhere in the program.
; If the target window is inactive when starting to scroll, it will be activated.
;
; Install https://www.autohotkey.com/ (Windows only) to run.
; To auto-start, copy the script or a shortcut to your
; Start Menu\Programs\Startup directory
; (%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup)
;
; BUGS:
; Makes tabSwitchAnywhereKey trigger on release, not on click. That's bad for fast games. xD
; Sometimes the tab switch activates randomly
; It's also triggered when using mouse wheel in a web page's select menus, for some reason
; Area to enable tab wheel scroll. ~45 for tab bar, ~80 to include address bar
tabAreaHeight := 80
; Key or button to enable tab scrolling anywhere in the program. RButton for right mouse button, MButton for Middle/Wheel button.
tabSwitchAnywhereKey := "MButton"
; List of WindowClass: "Descriptions". Change a program's "Description" to False to disable it.
enabledPrograms := {Chrome_WidgetWin_1: "Chrome, Chromium", MozillaWindowClass: "Firefox", IEFrame: "Internet Explorer", ApplicationFrameWindow: "Edge", "Notepad++": "Notepad++", TMainForm: "HeidiSQL - heidisql.exe", "SunAwtFrame_NotWorking": "IntelliJ Idea - idea64.exe", AcrobatSDIWindow: "Adobe Acrobat DC Pro", Solitaire: False}
VERSION := 3
#NoEnv ; Disable using enviroment variables without calling EnvGet(), for performance.
#Warn ; Detect common errors.
#SingleInstance force
#UseHook Off ; Using the keyboard hook is usually preferred for hotkeys - but here we only need the mouse hook.
#InstallMouseHook
#MaxHotkeysPerInterval 1000 ; Avoids warning messages for high speed wheel users.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
Menu, Tray, Tip, TabsOnWheels %VERSION%
Menu, Tray, Icon, imageres.dll, 306
; Register tabSwitchAnywhereKey to make it a prefix and prevent its normal behaviour
Hotkey, %tabSwitchAnywhereKey% & WheelUp, TabsOnWheels
Hotkey, %tabSwitchAnywhereKey% & WheelDown, TabsOnWheels
; Enable tabSwitchAnywhereKey when clicked by itself
Hotkey, %tabSwitchAnywhereKey%, SendThisHotkey
WheelUp::
WheelDown::
;RButton & WheelUp::
;RButton & WheelDown::
Gosub TabsOnWheels
Return
SendThisHotkey:
Send {%A_ThisHotkey%}
Return
TabsOnWheels:
;; Compare mouse position on the screen with the window beneath
;; to check if we are in the tab area
CoordMode, Mouse, Screen
MouseGetPos, mouseXPos, mouseYPos, winId
WinGetPos, winXPos, winYPos, winWidth, winHeight, ahk_id %winId%
WinGetClass, winClass, ahk_id %winId% ; Get Window class
; Check if we got an enabled class, and if pointer is over tab bar or tabSwitchAnywhereKey is pressed
If (enabledPrograms.hasKey(winClass) AND (GetKeyState(tabSwitchAnywhereKey, "P") OR (mouseYPos > winYPos and mouseYPos < winYPos + tabAreaHeight)))
{
IfWinNotActive ahk_id %winId%
WinActivate ahk_id %winId% ; Focus target window
If A_ThisHotkey in WheelUp,%tabSwitchAnywhereKey% & WheelUp
Send ^+{Tab}
Else
Send ^{Tab}
}
Else
{
Send {%A_ThisHotkey%}
}
Return
@opgary
Copy link

opgary commented Jun 27, 2020

Hi, I use WinGetClass and receive the class like this:
HwndWrapper[**.exe;;bbf63723-b032-4ff2-bc2d-50a5aa9b6a48]
And the bbf
a48 part will change during using the application.
How can I enable this ahk on such class?

@Chematronix
Copy link
Author

Hmmm, it should match if you simply add HwndWrapper: "VisualStudio" to enabledPrograms, me thinks.
Or enable regex matching (SetTitleMatchMode, 2 IIRC) for more complex matching HwndWrapper[.*;;[\da-f-]+], if there's another window with HwndWrapper.

Or, you could switch to Intellij. :)

I'm about to update to my latest version, BTW. Enjoy!

@Chematronix
Copy link
Author

Actually, I was lazy, v4 only matches exact class names. You might want to stick with v3 for now. :)

@I2obiN
Copy link

I2obiN commented Feb 19, 2021

Not working on Win 10, autohotkey v1. Tried installing current hotkey version and just got a 7zip error

image

@Chematronix
Copy link
Author

Not working on Win 10, autohotkey v1. Tried installing current hotkey version and just got a 7zip error

Updated the code, try again please. You might still need to update your AHK (I'm using v1.1.30.03).

There's a weird glitch when a select menu is open in a webpage, so don't scroll through tabs until you close it.

I might redo this from scratch, stay tuned!

@I2obiN
Copy link

I2obiN commented Feb 21, 2021

image

I think it's complaining about the curly brace but not sure

@Chematronix
Copy link
Author

Chematronix commented Feb 21, 2021

Did you download the code again? If so, you need to update your AHK (I'm using 1.1). You can try the latest 1.1 installer:
https://www.autohotkey.com/download/1.1/AutoHotkey_1.1.33.02_setup.exe

@I2obiN
Copy link

I2obiN commented Feb 21, 2021

Yeh AHK's executable setup files are messed up. I just get a 7zip error, had to take the zip file then run their installation script from that to get it installed. No issues running on the version you mentioned. Kind of a disaster on AHK's part but if anyone else sees this thread they'll know how to resolve it. Thanks for looking at it much appreciated!

@I2obiN
Copy link

I2obiN commented Feb 21, 2021

Error in question:
image

@I2obiN
Copy link

I2obiN commented Feb 21, 2021

Think I came across that weird glitch/bug. If I roll to a different tab then scroll down normally it kinda lags a bit and the script fails. I need to reload to get it working again.

@Chematronix
Copy link
Author

Yeah, seems I'm stretching the limits of AHK. And I'm not even trying!

You could try v3, let me know if that's better:
https://gist.github.com/Chematronix/5d7e12f7e580652aac46dc8080906e4f/95004b72804d868e9e1b3d8e2d73b570460ada14

@I2obiN
Copy link

I2obiN commented Feb 21, 2021

Working like a charm now. Thanks!

@Chematronix
Copy link
Author

With v3?

@I2obiN
Copy link

I2obiN commented Feb 21, 2021

Yep V3 no issues as long as I hover over the tabs or the address bar. It does bring up the menu though but not a big deal.

@Chematronix
Copy link
Author

Chematronix commented Feb 21, 2021

Cool. Might just scrap v4. xD
Do you mean right click menu? You don't need to click it if you're over the tabs. V3 uses middle click to switch tabs on the rest of the window by default, but you can change MButton to RButton to switch it to right click.

@nothinglastsforever
Copy link

Could I add Adobe Acrobat DC Pro to this? Have a lot of PDF open at once.

@nothinglastsforever
Copy link

Tried adding
, AcrobatSDIWindow: "Adobe Acrobat DC Pro"
but resulted in the script crashing

@Chematronix
Copy link
Author

Reverted to v3, added Acrobat DC, and a list of bugs. Check it out @nothinglastsforever!

@nothinglastsforever
Copy link

nothinglastsforever commented May 19, 2021

@Chematronix thanks so much, mate! I've wanted this for so long. How do I buy you a beer?
One minor quibble, I've noticed this script prevents middle mouse button click and drag scrolling. Is this something that can be fixed or a trade-off? I've attached a screen recording to demonstrate.

https://streamable.com/ozfbfx

@sd016808
Copy link

sd016808 commented Jan 14, 2022

@ataberk1907
Copy link

When Caps lock is on, the script triggers every time I scroll up or down. Caps Lock turns "off" and immediately turns "on" back and shows OSD. How to solve it, what is the problem?

@SkullHex2
Copy link

Can you add support to AutoHotKey v2.0?

@vysmaty
Copy link

vysmaty commented Apr 8, 2024

I don't know if I missed some fix from @sd016808 – now that I'm looking at it.

But here is the modified version for v2 and some conditions for running. Disabling MButton completely or not blocking it. + Vivaldi:

https://gist.github.com/vysmaty/4ec8e83a569a33ae1b66084736e03b08

And thanks a lot @Chematronix !

@Chematronix
Copy link
Author

Chematronix commented Apr 14, 2024 via email

@vysmaty
Copy link

vysmaty commented Apr 20, 2024

I could move this to an actual repo, to facilitate merging. What's good about AHK v2? All my scripts are still v1 and w

Repo sounds like a good idea. I'm still getting the hang of repos, but it's kind of working for me.

I don't really know what advantages to disadvantages AHK v2 has. It seems to me that everything is like a function or object in AHK v2 and it's somehow more consistent. But for me scripting is just a hobby, so what i now?

I solved running both v1 and v2 by: AHK Startup v2. The author converted it into a new version. Without that I wouldn't go into v2 at all. After all, autohotkey is a set of tools for me to work with and I will not break my workflow unnecessarily. https://www.autohotkey.com/boards/viewtopic.php?f=83&t=120981&p=536860&hilit=AHK+Startup#p536860

You can use for conversion to v2 https://github.com/mmikeww/AHK-v2-script-converter , but anyway, one ends up in docs wondering what the replacement for some function is... and fiddling around in arrays -> maps -> objects.

So I've taken things one at a time from simple. I tweaked a few things here and there, and when it looked like it would be better not to dig into it, I left it in v1. AHK Startup has been a god thing for me for years and one doesn't really have to worry about it too much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment