Reputation: 5359
I'm trying to remap my Surface Pen button click to pause/unpause youtube in Chrome. I can get it to work if Chrome is not focused, or if Chrome is focused and youtube is the active tab, but it doesn't work if Chrome is focused but youtube is not the active tab.
This is what I have:
#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.
SetTitleMatchMode 2
#IfWinNotActive, ahk_exe chrome.exe
#F20::
ControlGet, controlID, Hwnd,,Chrome_RenderWidgetHostHWND1, Google Chrome
ControlFocus,,ahk_id %controlID%
tabCount := 0
Loop {
IfWinExist, YouTube
break
ControlSend, , ^{PgUp} , Google Chrome
sleep 150
tabCount := tabCount + 1
if tabCount = 10
break
}
if tabCount < 10
ControlSend, , k , Google Chrome
Loop, %tabCount% {
ControlSend, , ^{PgDn} , Google Chrome
sleep 150
}
return
#IfWinNotActive
#IfWinActive, ahk_exe chrome.exe
#F20::
tabCount := 0
Loop {
IfWinExist, YouTube
break
ControlSend, , ^{PgUp} , Google Chrome
sleep 150
tabCount := tabCount + 1
if tabCount = 10
break
}
if tabCount < 10
ControlSend, , k , Google Chrome
Loop, %tabCount% {
ControlSend, , ^{PgDn} , Google Chrome
sleep 150
}
return
#IfWinActive
Upvotes: 0
Views: 539
Reputation: 5359
Turns out this is enough:
#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.
#F20::Media_Play_Pause
Upvotes: 1