Skip to content

Instantly share code, notes, and snippets.

@xamgore
Created March 15, 2017 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xamgore/1691b0d07df6f9e967cff5b5405a97b9 to your computer and use it in GitHub Desktop.
Save xamgore/1691b0d07df6f9e967cff5b5405a97b9 to your computer and use it in GitHub Desktop.
; Note: the encoding of this file SHOULD be "UTF-8 with BOM".
; Emulate mouse-wheel tab switching on google-chrome/iron (windows version).
;
; Keys:
; • mouseWheelUp : switch to previous tab (only if the mouse is above )
; • mouseWheelDown : switch to next tab (the google-chrome/iron tab bar)
;
; Strangely, google refuses to add this feature on the windows version of google-chrome.
;
; This script also works with iron (web browser based on chromium, with less privacy issues):
; http://www.srware.net/en/software_srware_iron_chrome_vs_iron.php
;
; Limitation: the browser needs to be the active window.
; I don't plan to change that. However, to have a focus-follow-mouse behaviour,
; you can check out http://joelpurra.com/Projects/X-Mouse_Controls/.
;
; Hacking: if you want to adapt this script to your own needs, you may be also
; interested in looking at MouseWheelTabScroll4Chrome.ahk, that addresses the
; same issue:
; - google+ thread : https://plus.google.com/115670442023408995787/posts/WYPqqk2j9UB
; - ahk source code : https://drive.google.com/?usp=chrome_app#folders/0ByBbgFg_gObJTmdFd29PWEVwVHc
#NoEnv
#SingleInstance force
SendMode Input ; faster and more reliable
SetWorkingDir %A_ScriptDir% ; ensures a consistent starting directory
SetWinDelay,2 ; get it smooth
;SetKeyDelay, 0, 1 ; NOTE: Needed if we use ControlSend instead of SendInput. When using SendInput, it makes the scroll slower.
CoordMode, Mouse, Screen ; always consider absolute mouse position
tabBarYMin := 19 ; Y-position of the tab bar (min)
tabBarYMax := 44 ; Y-position of the tab bar (max)
SwitchTabs(n) {
global tabBarYMin
global tabBarYMax
MouseGetPos, mouseX0, mouseY0, winId
WinGetClass, winClass, ahk_id %winId%
if (winClass = "Chrome_WidgetWin_1") {
WinGetPos, winUpLeftX0, winUpLeftY0, , , ahk_id %winId%
; offset from the window position
MouseGetPos, mouseX, mouseY
mouseDX := mouseX - winUpLeftX0
mouseDY := mouseY - winUpLeftY0
if (tabBarYMin <= mouseDY and mouseDY <= tabBarYMax) {
while (n < 0) {
SendInput ^{PgUp}
;ControlSend, , ^{PgUp}, ahk_id %winId%
n++
}
while (n > 0) {
SendInput ^{PgDn}
;ControlSend, , ^{PgDn}, ahk_id %winId%
n--
}
}
}
return
}
Return
~WheelUp::
SwitchTabs(-1)
Return
~WheelDown::
SwitchTabs(1)
Return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment