Tab switching in chrome with mouse wheel and multiple desktops switching.
Since I am a long time Linux user, I have some habits that I’v gotten used to and can’t really live without. One is the ability to switch between multiple virtual desktops with WIN + 1-4. and opening browser with WIN + W and the last one that is really important is being able to scroll on the tabs in the web browser to scroll through them. Unfortunately the scrolling on tabs is disabled in windows version of chrome, but I found a way to at least be able to scroll without using my keyboard. This script makes it possible for you to switch tabs if you press and hold right mouse button and scroll at the same time.
First of all, download and install AutoHotKey. A free and must-have program that make it possible for us to make our own keybindings. Then just make a new text file with the .ahk extension and add following:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#If (WinActive("ahk_class Chrome_WidgetWin_1") or Winactive("ahk_class IEFrame")) ; Chrome or IE
+WheelUp:: Send,{CtrlDown}{Tab}{CtrlUp}
+WheelDown:: Send, {CtrlDown}{ShiftDown}{Tab}{ShiftUp}{CtrlUp} ; "+" means Shift
RButton & WheelUp:: Send ^{PgUp}
RButton & WheelDown:: Send ^{PgDn}
RButton Up:: Click Right
#If
If you want to be able to open chrome with WIN +W, just add this line at the end:
#w::Run chrome.exe
Then save and double click on the .ahk file that you created and the script will run. And if you want to run it at startup, then hit WIN + r and run shell:startup. Then paste your script into the startup folder and you are done.
Now to one of the most important thing to have to be able to be somewhat productive, multiple desktops. Now in windows 10 they finally got multiple desktops available, but not a way to customize your keyboard shortcuts for switching between them, but luckily I found a script somewhere a while back, so I cant take credit for this one, but I’ll share it. Just do the same as with previous script and you will be able to switch between desktops with WIN + 1,2,3,4… To create more desktops press WIN + TAB and click on the + sign and you can get going.
#NoTrayIcon
#Persistent
; #SingleInstance force
; #KeyHistory 0
; #InstallKeybdHook
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SetBatchLines -1
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
main(), return
RunHotkey:
switchToDesktop(StrReplace(A_ThisHotkey, "#", , , 1) - 1)
return
switchToDesktop(idx)
{
global ppDesktopManager, IID_IVirtualDesktop
DllCall(vtable(ppDesktopManager, 7), "Ptr", ppDesktopManager, "Ptr*", pDesktops)
if (pDesktops) {
DllCall(vtable(pDesktops, 4), "Ptr", pDesktops, "UInt", idx, "Ptr", &IID_IVirtualDesktop, "Ptr*", VirtualDesktop)
if (VirtualDesktop) {
DllCall(vtable(ppDesktopManager, 9), "Ptr", ppDesktopManager, "Ptr", VirtualDesktop)
ObjRelease(VirtualDesktop) ; I assume these should be freed
}
ObjRelease(pDesktops)
}
}
main()
{
OnExit, cleanup
OnMessage(DllCall("RegisterWindowMessage", Str, "TaskbarCreated"), "WM_TASKBARCREATED")
static ImmersiveShell := ComObjCreate("{C2F03A33-21F5-47FA-B4BB-156362A2F239}", "{00000000-0000-0000-C000-000000000046}")
global IID_IVirtualDesktop, ppDesktopManager
try ppDesktopManager := ComObjQuery(ImmersiveShell, "{C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B}", "{f31574d6-b682-4cdc-bd56-1827860abec6}")
if (!ppDesktopManager)
ppDesktopManager := ComObjQuery(ImmersiveShell, "{C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B}", "{AF8DA486-95BB-4460-B3B7-6E7A6B2962B5}")
GUID(IID_IVirtualDesktop, "{FF72FFDD-BE7E-43FC-9C03-AD81681E88E4}")
ObjRelease(ImmersiveShell)
Loop 9
Hotkey, #%A_Index%, RunHotkey
return
cleanup:
if (ppDesktopManager)
ObjRelease(ppDesktopManager)
ExitApp
}
WM_TASKBARCREATED()
{
Reload
}
vtable(ptr, n) {
; NumGet(ptr+0) returns the address of the object's virtual function
; table (vtable for short). The remainder of the expression retrieves
; the address of the nth function's address from the vtable.
return NumGet(NumGet(ptr+0), n*A_PtrSize)
}
GUID(ByRef GUID, sGUID) ; Converts a string to a binary GUID
{
VarSetCapacity(GUID, 16, 0)
DllCall("ole32\CLSIDFromString", "Str", sGUID, "Ptr", &GUID)
}
Hey!
A wild casual ql player appears. If you like hotkeys I suggest checking out vimium from chrome. It’s using vim shortcuts in the browser. Vim is a text editor I use daily at work (I’m a software engineer). I can go almost full mouseless with this :>
hf
Cool cool. I mostly use nano nowadays actually, did use vim years ago, but I basically forgot everything about it now 😀 But sounds really cool though. Thanks for the tip!