Home » Questions » Computers [ Ask a new question ]

How can I use Autohotkey to focus on an existing Google Chrome tab, not a "container" window?

How can I use Autohotkey to focus on an existing Google Chrome tab, not a "container" window?

How can I use Autohotkey to focus on an existing Google Chrome tab, not a "container" window?

Asked by: Guest | Views: 83
Total answers/comments: 4
Guest [Entry]

"Workaround using Alt+Tab:

; Activates the window identified with wintitle if it's active,
; else opens a new one
OpenWindow(wintitle, runCommand)
{
if WinExist(wintitle)
WinActivate ; activates the window found above. Sweet.
else
Run %runCommand%
}

#g::
AppsKey & g::
prevKeyDelay := A_KeyDelay
SetKeyDelay, 100
OpenWindow(""ahk_class Chrome_WidgetWin_0"", A_AppData
. ""\Local\Google\Chrome\Application\chrome.exe"")
SendEvent {Alt down}{Tab}
SendEvent +{Tab}
SendEvent {Alt up}
SetKeyDelay, prevKeyDelay
return

Adjust arguments as needed. SetKeyDelay used because sending too fast does not work."
Guest [Entry]

"There seems to be a bug with the WinActivate function in AutoHotkey. (http://productivegeek.com/forums/topic/autohotkey-problem-restoring-minimized-window-and-giving-keyboard-focus)

So instead of the WinActivate line, use

WinGet, winid, ID,
DllCall(""SwitchToThisWindow"", ""UInt"", winid, ""UInt"", 1)"
Guest [Entry]

"!f::
IfWinExist ahk_class Chrome_WidgetWin_0
{ IfWinActive ahk_class Chrome_WidgetWin_0
{ Loop, 60
{ GetKeyState, state, C
if state = D
{ KeyWait, c

KeyWait, LAlt
Sleep 10

;must send RCtrl!!!
Send {RCtrl down}
Send {w down}
Sleep 10
Send {w up}
Send {RCtrl up}

break
}
Sleep 1
}

}

else
{ KeyWait,f
KeyWait,LAlt
;don't hijack other apps
Send f
}
}

return"
Guest [Entry]

"See if this helps or gives you more ideas. I am not using any of the above.

!z::
WinWait, Yahoo,
IfWinNotActive, Yahoo, , WinActivate,Yahoo,
WinWaitActive, Yahoo,
Sleep, 100
return"