Pause video in browser doesn't work

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AndrewKun
Posts: 24
Joined: 03 Jun 2015, 12:03

Pause video in browser doesn't work

23 Feb 2016, 16:26

Hi,
I'm having a little trouble with the following situation - let's say I'm watching a video on YouTube, or other web player that support pausing the video with spacebar.

I want to create a script that would do the following when I press "space":
1. send a "space" to the web player to pause the video
2. sleep 500 ms
3. send "win+d" combination to hide the browser window

When I press "space" again, it should do the opposite (with a little modification):
1. send "win+d" to show browser window again
2. sleep 500 ms
3. send "left arrow key" once to rewind a little (YouTube supports that)
4. sleep 500 ms
5. send "space" to resume playing

Well, it doesn't have to be all on one button, it could be 2 buttons for each sequence. The problem is when I try to send "space" it doesn't work. I tried Send, SendInput, SendPlay, SendRaw, tried {space} and vk20, but still the video doesn't pause. However when the script is disabled and I press space normally, the video DOES pause. I can't understand what's the different between the normal "space" press and when AHK send the "space" to browser, but the later doesn't work.

I'd be grateful for any hints on what could be the problem.
User avatar
boiler
Posts: 16915
Joined: 21 Dec 2014, 02:44

Re: Pause video in browser doesn't work

23 Feb 2016, 16:29

What are you doing to have the space sent to the browser window? Are you activating that window before you send the space? Are you using ControlSend to send it to that window specifically?
User avatar
Almost_there
Posts: 404
Joined: 30 Sep 2014, 10:32

Re: Pause video in browser doesn't work

23 Feb 2016, 16:34

One hint: Show what you have so far. Also what web browser you're running. Have you tried other hotkeys to the same browser? Do they work as expected?
AndrewKun
Posts: 24
Joined: 03 Jun 2015, 12:03

Re: Pause video in browser doesn't work

23 Feb 2016, 16:52

I simply tried this so far for the first half of the script:

vk20::
Send, vk20 (tried SendInput, SendPlay, SendRaw e.t.c, doesn't work)
sleep, 500
send, #d (this works as expected)
return

I use Chrome, and the window is already active when I run the script, so I didn't try ControlSend. Actually, I don't know how to use ControlSend here because the window title is always different (the name of the page).
Also, the space doesn't get send to any application I tried, even notepad. I'm clearly doing it wrong.
User avatar
boiler
Posts: 16915
Joined: 21 Dec 2014, 02:44

Re: Pause video in browser doesn't work

23 Feb 2016, 20:38

The window being open or even active when you run the script won't make the space go to that window because the focus goes to the window that you clicked on to run the script. It's just like if you were doing it manually, you can't just send a space when Notepad is open and expect it to go to the browser window. You can click on the browser window before you click the hotkey. Try that first. And if you want to activate Chrome from the script, you can use ahk_exe chrome.exe as the title.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Pause video in browser doesn't work

23 Feb 2016, 22:28

Two (Three) things:

1) it should be Send, {vk20}
1b) Why not just use Space:: and Send, {Space}?
2) You may need to use the $ modifier or #UseHook to prevent recursion when you make that change. $vk20:: or $Space::.

An alternative is actually do just use ~vk20::Send #d, but it may need to be expanded to

Code: Select all

~vk20::
Sleep 50
Send #d
return
(Of course, substituting Space for vk20 is still applicable.)
AndrewKun
Posts: 24
Joined: 03 Jun 2015, 12:03

Re: Pause video in browser doesn't work

24 Feb 2016, 14:29

Thank you very much for the answers guys. I couldn't get ControlSend to work for some reason, but the problem was in the recursion as Exaskryz hinted. After adding $ modifier script started to work, partially, but YouTube still had focusing problems, so instead I used MouseClick to do what I want and it works perfectly :) I found another AHK script to get mouse position and used it like this:

Code: Select all

$space::
MouseClick, left, 420, 840
sleep 1000
send #d
sleep 1000
MouseClick, left, 420, 840
return
Not the cleanest solution, since it sends unnecessary clicks, but at least I can use one button to pause-hide and restore-play, and can pinpoint my cursor to any tiny play button in any web player.
Thanks again!
User avatar
Almost_there
Posts: 404
Joined: 30 Sep 2014, 10:32

Re: Pause video in browser doesn't work

25 Feb 2016, 13:56

One thing that might help is to make sure the mouse pointer goes back to the original position.

I use an massive mouse-click-intensive program at work that about any operation needs to be done by mouse click. I've made this sipmple function:

Code: Select all

klikkReturn(xvar, yvar) {
	MouseGetPos, musX, musY
	MouseMove, xvar, yvar, 0
	Send {LButton}
	MouseMove, musX, musY, 0
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333, onurcoban and 366 guests