Send keys to YouTube window which is playing music/video

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
scriptor2016
Posts: 863
Joined: 21 Dec 2015, 02:34

Send keys to YouTube window which is playing music/video

21 Nov 2020, 22:51

Hi everyone

Just sitting around here tonight, conjuring up some ideas on what sort of code to tackle next.

Let's say we have multiple Google Chrome windows (not tabs) open, and a few of them are on Youtube.

One of them is playing a video. The rest of them are also on videos, but are not playing right now.

Next, say we open up a notepad window or something and begin typing anything into it. The Chrome window which is playing the video is now inactive.

Is there a possibile way to send a keystroke to this particular inactive window (in order to play/pause) the video? Can there be a way to isolate which exact Chrome window is playing content and then send a keystroke to it.

The only way I can think of is to loop through all Youtube windows, and send the appropriate keystroke to all those windows one-by-one. The problem is, it would stop the window which is playing the video, but then also start playing all the other ones.

This is just food for thought. Just for fun. If no replies it's cool. Just thought maybe somebody already had something like this in their collection of scripts :)
User avatar
mikeyww
Posts: 27102
Joined: 09 Sep 2014, 18:38

Re: Send keys to YouTube window which is playing music/video

22 Nov 2020, 07:06

I imagine that there might be a browser call or way to use Chrome.ahk to accomplish this. One simple alternative: if you use AHK to activate the initial play action, then you could retrieve the window's ID at that time, and you would then know which window to target for the toggle.

Code: Select all

F3::                                      ; Toggle play after initial play has occurred (see below)
If WinExist(chromePlaying)
 WinExist("A")
Else Return
WinActivate, %chromePlaying%
Send {Space}
WinActivate
Return

#IfWinActive ahk_exe chrome.exe
F4::                                      ; Initial play
WinGetActiveTitle, wTitle
If Instr(wTitle, "YouTube") {
 chromePlaying := "ahk_id " WinExist("A")
 Send {Space}
} Else MsgBox, 48, Error, YouTube tab is not active.
Return
scriptor2016
Posts: 863
Joined: 21 Dec 2015, 02:34

Re: Send keys to YouTube window which is playing music/video

22 Nov 2020, 14:53

ah-ha! awesome! that works just as well :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Darkmaster006, OrangeCat, Rohwedder and 168 guests