Tab switching hotkeys for Chrome/Firefox

Post your working scripts, libraries and tools for AHK v1.1 and older
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Tab switching hotkeys for Chrome/Firefox

02 Jul 2016, 20:31

Tab and release: Sends Tab.
Tab & 1-9: Sends Ctrl+n (generally activates the nth tab).
Tab & q: Previous tab.
Tab & w: Sends Alt+D (generally focuses address bar).
Tab & e/Space: Next tab.

Applies to: Chrome 51 (and some older versions), Firefox (not tested recently)

Back-story:
I recently replaced my keyboard and I'm finding it harder to push Ctrl+Shift+Tab reliably, so I started to look in my hotkey script for the section specific to browsers, to add an easier hotkey for "previous tab". It turns out I already had a bunch of hotkeys for this purpose, written years ago and forgotten about. So I'm posting about them to aid my memory. :lol:

Code: Select all

; In the auto-execute section:
GroupAdd, WebBrowser, Google Chrome ahk_class Chrome_WidgetWin_0
GroupAdd, WebBrowser, Google Chrome ahk_class Chrome_WidgetWin_1
GroupAdd, WebBrowser, Mozilla Firefox ahk_class MozillaUIWindowClass
GroupAdd, WebBrowser, Mozilla Firefox ahk_class MozillaWindowClass
; Add browsers as needed.
; End auto-execute code.

#IfWinActive ahk_group WebBrowser
Tab::
    ; Temporarily enable Tab-combination hotkeys:
    Hotkey IfWinActive, ahk_group WebBrowser
    Loop 9
        Hotkey %A_Index%, Tab_n, On
    Hotkey Space, Tab_sp, On
    Hotkey q, Tab_q, On
    Hotkey w, Tab_w, On
    Hotkey e, Tab_e, On
    ; Use KeyWait rather than Tab up:: because the latter will execute
    ; even if Tab:: didn't execute - e.g. sometimes when Alt-Tabbing to
    ; the browser.  It also avoids the risk of the Tab-up being missed
    ; and these hotkeys not being turned off.
    KeyWait Tab
    ; Activate normal Tab function on key-release:
    if A_PriorKey = Tab
        Send {Tab}
    ; Turn off Tab-combination hotkeys:
    Loop 9
        Hotkey %A_Index%, Off
    Hotkey Space, Off
    Hotkey q, Off
    Hotkey w, Off
    Hotkey e, Off
    return
Tab_n:
    Send % "^" A_ThisHotkey
    return
Tab_q:
    Send ^+{Tab}
    return
Tab_w:
    Send !d{End}
    return
Tab_e:
Tab_sp:
    Send ^{Tab}
return
I think I avoided custom combinations (e.g. Tab & q::) because of the effect they have on other hotkeys involving Tab.
guest3456
Posts: 3462
Joined: 09 Oct 2013, 10:31

Re: Tab switching hotkeys for Chrome/Firefox

02 Jul 2016, 21:14

the chrome extension Vimium allows you to tab left/right with J and K respectively, along with hosts of other shortcuts in the same vein as Vim keystroke movements. i also use it for mouseless browsing, since i can open links with keystrokes too

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Tab switching hotkeys for Chrome/Firefox

02 Jul 2016, 21:56

I don't use Vim; tried it once and didn't like the input scheme. I also tend not to use third-party software (even browser extensions) for things that are easily solved with a few simple hotkeys.

I do use an extension called Type-ahead-find, which can be used for activating links by searching. So can the normal search function, but you need to escape out of the search box in order to focus the link.
User avatar
rommmcek
Posts: 1473
Joined: 15 Aug 2014, 15:18

Re: Tab switching hotkeys for Chrome/Firefox

05 Jul 2016, 12:43

@guest3456: The catch is to switch between Tabs in one-handed non prestidigitatorial way, I guess. Here is what I'm using since I know AutoHotkey:

Code: Select all

#if WinActive("ahk_exe chrome.exe") or WinActive("ahk_exe SciTE.exe")
	^+WheelDown::Send, ^{PGDN}
	^+WheelUp::Send, ^{PGUP}
	^CapsLock::Send, ^{PGUP}
	^Tab::Send, ^{PGDN}
#if
@Lexikos: I have read your dissuasion about using #if WinActive(), but I have no truble and spare couple of lines. Nevertheless I like your coding, who don't!
guest3456
Posts: 3462
Joined: 09 Oct 2013, 10:31

Re: Tab switching hotkeys for Chrome/Firefox

06 Jul 2016, 00:46

i didnt even know of the Ctrl+PgDn shortcuts, so thanks :)

Ved
Posts: 20
Joined: 15 Jul 2016, 19:06

Re: Tab switching hotkeys for Chrome/Firefox

15 Jul 2016, 19:13

[Moderator's note: The guest post which this is a duplicate of was deleted.]

Sorry for previous post,XD

Function for search and focus tab:

Code: Select all

#IfWinexist,ahk_class MozillaWindowClass
w & f1::BUSCARPESTAÑAPORNOMBRE("WhatsApp Web") ;ACTIVAR PESTAÑA ESPECIFICA NOMBRE INI
f & f1::BUSCARPESTAÑAPORNOMBRE("Facebook")
n & f1::BUSCARPESTAÑAPORNOMBRE("my.tv")
e & f1::BUSCARPESTAÑAPORNOMBRE("Geraspora")
y & f1::BUSCARPESTAÑAPORNOMBRE("YouTube")
v & f1::BUSCARPESTAÑAPORNOMBRE("youtuve tv")
a & f1::BUSCARPESTAÑAPORNOMBRE("Audio Exp ")
h & f1::BUSCARPESTAÑAPORNOMBRE("yourmail")
s & f1::BUSCARPESTAÑAPORNOMBRE("SoundCloud")
b & f1::BUSCARPESTAÑAPORNOMBRE("movies & downstar")
i & f1::BUSCARPESTAÑAPORNOMBRE("Hispasonic")
g & f1::BUSCARPESTAÑAPORNOMBRE("Musiclowless")



BUSCARPESTAÑAPORNOMBRE(nombrepestaña)
{ winactivate,ahk_class MozillaWindowClass
Loop,30
{send,^{Tab}
wingettitle,pestañaactual,ahk_class MozillaWindowClass
if pestañaactual contains %nombrepestaña%
{send,^+{Tab}
break
}sleep 200
}} ;ACTIVAR PESTAÑA ESPECIFICA NOMBRE FIN
av930
Posts: 31
Joined: 24 Dec 2017, 10:21

Re: Tab switching hotkeys for Chrome/Firefox

01 Apr 2018, 08:27

Is this working? I tried to find some script to switch tab previous and next.
when I put "tab+ anykey" nothing happen

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: Chunjee, Epoch, Google [Bot] and 51 guests