autohotkey - AutoHotKey 播放/暂停 Youtube
问题描述
我正在尝试重新映射我的 Surface Pen 按钮单击以在 Chrome 中暂停/取消暂停 youtube。如果 Chrome 没有聚焦,或者 Chrome 聚焦并且 youtube 是活动选项卡,我可以让它工作,但如果 Chrome 聚焦但 youtube 不是活动选项卡,它就不起作用。
这就是我所拥有的:
#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
解决方案
事实证明这已经足够了:
#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
推荐阅读
- java - 无法转换 java.lang.Boolean 类型的对象
- java - 为什么 @Configuration 类被 cglib 代理与 ConfigurationClassEnhancer 类包装
- java - 使用 mockito 时出现空指针异常
- django - django 1.4 中没有名为 py 的模块
- r - 如何使用'knnImpute'在R(插入符号)中修复“dimnames(x)<-dn中的错误:'dimnames'[2]的长度不等于数组范围”
- vue.js - 一个 Vue.Js 简单示例给了我一个空白页
- reactjs - 如何从 API 接收的数组在 Redux 中创建分页
- wordpress - 无法使用 2 个 wordpress 实例连接到我的数据库 - swarm 已禁用?
- javascript - 如何将 ajax $.get 值传递给 jQuery 中的另一个 $.get 函数?
- javascript - 通过 Ajax 提交表单后,提交按钮被冻结