AutoHotKey Play / Pause Youtube - PullRequest
       15

AutoHotKey Play / Pause Youtube

0 голосов
/ 17 апреля 2020

Я пытаюсь переназначить нажатие кнопки Surface Pen, чтобы приостановить / отменить приостановку youtube в Chrome. Я могу заставить его работать, если 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

1 Ответ

1 голос
/ 17 апреля 2020

Оказывается, этого достаточно:

    #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
...