YouTube Key Remap

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jack3333
Posts: 12
Joined: 15 Nov 2017, 14:49

YouTube Key Remap

21 Dec 2017, 09:50

Hi, is it possible to remap the F key to F11 ONLY when I'm browsing YouTube?
I use Opera browser, but if I write something like this:

Code: Select all

#IfWinExist, ahk_exe opera.exe
F::F11
it applies to the browser, to every site. I need it to only work for YouTube.
Thanks in advance!
teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: YouTube Key Remap

21 Dec 2017, 12:09

Hi, jack3333,

Try:

Code: Select all

SetTitleMatchMode, 2
#If WinActive("YouTube - Opera ahk_exe opera.exe")
F::F11
jack3333
Posts: 12
Joined: 15 Nov 2017, 14:49

Re: YouTube Key Remap

21 Dec 2017, 18:51

teadrinker wrote:Hi, jack3333,

Try:

Code: Select all

SetTitleMatchMode, 2
#If WinActive("YouTube - Opera ahk_exe opera.exe")
F::F11
It doesn't work. I'm not sure if this matters but the title of the tab doesn't start with "YouTube -"
It's at the end: *video title* - YouTube
teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: YouTube Key Remap

21 Dec 2017, 20:39

jack3333 wrote:It's at the end: *video title* - YouTube
In that case try this:

Code: Select all

SetTitleMatchMode, 2
#If WinActive("- YouTube ahk_exe opera.exe")
F::F11
jack3333
Posts: 12
Joined: 15 Nov 2017, 14:49

Re: YouTube Key Remap

21 Dec 2017, 21:40

teadrinker wrote:
jack3333 wrote:It's at the end: *video title* - YouTube
In that case try this:

Code: Select all

SetTitleMatchMode, 2
#If WinActive("- YouTube ahk_exe opera.exe")
F::F11
Still doesn't work. The thing is that the F key is the default YouTube fullscreen, but when you enter fullscreen like this, you can't scroll down the site.
When you press F11 the browser enters fullscreen, and now you can scroll down and explore the site normally.

BTW

Code: Select all

#IfWinExist, ahk_exe opera.exe
f::F11
This works, but I only want it to work when I'm on YouTube.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: YouTube Key Remap

21 Dec 2017, 21:58

To be clear, what is your full code?

teadrinker is using the SetTitleMatchMode command. Have you set this command into your auto-execute section? If you have not, that can explain the problems. Use the Window Spy which can be accessed by right-clicking the tray icon (by the system clock) of a running script to verify the window title.
teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: YouTube Key Remap

21 Dec 2017, 22:06

Exaskryz wrote:Have you set this command into your auto-execute section?
Yes, SetTitleMatchMode, 2 must be at the beginning of the script.
jack3333
Posts: 12
Joined: 15 Nov 2017, 14:49

Re: YouTube Key Remap

21 Dec 2017, 22:30

Exaskryz wrote:To be clear, what is your full code?

teadrinker is using the SetTitleMatchMode command. Have you set this command into your auto-execute section? If you have not, that can explain the problems. Use the Window Spy which can be accessed by right-clicking the tray icon (by the system clock) of a running script to verify the window title.
teadrinker wrote:
Exaskryz wrote:Have you set this command into your auto-execute section?
Yes, SetTitleMatchMode, 2 must be at the beginning of the script.
This:

Code: Select all

SetTitleMatchMode, 2
#If WinActive("- YouTube ahk_exe opera.exe")
f::F11
Doesn't work.

But this, and only this:

Code: Select all

#IfWinExist, ahk_exe opera.exe
f::F11
works.

The Window Spy tool doesn't show any difference. No matter which tab I click it's the same.
teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: YouTube Key Remap

21 Dec 2017, 22:35

What window title does Window Spy show?
jack3333
Posts: 12
Joined: 15 Nov 2017, 14:49

Re: YouTube Key Remap

21 Dec 2017, 22:42

teadrinker wrote:What window title does Window Spy show?
*Title of the video I'm watching* - YouTube - Opera
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: YouTube Key Remap

21 Dec 2017, 22:48

Try this:

Code: Select all

SetTitleMatchMode, 2
#If WinActive("- YouTube - Opera")
f::F11
Or since the #IfWinExist worked for you, we can try #IfWinActive,

Code: Select all

SetTitleMatchMode, 2
#IfWinActive, - YouTube - Opera
f::F11
I figure at this point if the window title includes - Opera we don't need to worry about the ahk_exe opera.exe part.
jack3333
Posts: 12
Joined: 15 Nov 2017, 14:49

Re: YouTube Key Remap

21 Dec 2017, 22:54

Exaskryz wrote:Try this:

Code: Select all

SetTitleMatchMode, 2
#If WinActive("- YouTube - Opera")
f::F11
Or since the #IfWinExist worked for you, we can try #IfWinActive,

Code: Select all

SetTitleMatchMode, 2
#IfWinActive, - YouTube - Opera
f::F11
I figure at this point if the window title includes - Opera we don't need to worry about the ahk_exe opera.exe part.

I tried the first one but it doesn't work. So I added the video title, and it did.
Obviously I can't do this for every video. My question is: don't we need a wildcard in the script?
Forgive my ignorance, but maybe something like this: * - YouTube - Opera
teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: YouTube Key Remap

21 Dec 2017, 23:12

Try:

Code: Select all

SetTitleMatchMode, Regex
#IfWinActive, .* - YouTube - Opera
f::F11
 
jack3333
Posts: 12
Joined: 15 Nov 2017, 14:49

Re: YouTube Key Remap

21 Dec 2017, 23:15

teadrinker wrote:Try:

Code: Select all

SetTitleMatchMode, Regex
#IfWinActive, .* - YouTube - Opera
f::F11
I thought that one was really going to work, but it didn't.
I'm starting to lose faith, it looks like it's not possible.
Maybe the problem is Opera?
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: YouTube Key Remap

21 Dec 2017, 23:35

Try just this in its own separate script. This should work and I have no reason to doubt it:

Code: Select all

SetTitleMatchMode, 2
#IfWinActive YouTube
f::MsgBox hello
We can start there. If the MsgBox appears, we can replace it with f::F11. If it doesn't, something wonky is going on.
jack3333
Posts: 12
Joined: 15 Nov 2017, 14:49

Re: YouTube Key Remap

21 Dec 2017, 23:43

Exaskryz wrote:Try just this in its own separate script. This should work and I have no reason to doubt it:

Code: Select all

SetTitleMatchMode, 2
#IfWinActive YouTube
f::MsgBox hello
We can start there. If the MsgBox appears, we can replace it with f::F11. If it doesn't, something wonky is going on.
It works! Wait, I was suppose to always use a new script?
All this time I've been adding this lines to an .ahk file where all my scripts are.
Maybe something there, was interfering.

EDIT: It works when I put the lines at the beginning of the script.
Last edited by jack3333 on 21 Dec 2017, 23:45, edited 1 time in total.
teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: YouTube Key Remap

21 Dec 2017, 23:45

teadrinker wrote:
Exaskryz wrote:Have you set this command into your auto-execute section?
Yes, SetTitleMatchMode, 2 must be at the beginning of the script.
:lol:
jack3333
Posts: 12
Joined: 15 Nov 2017, 14:49

Re: YouTube Key Remap

22 Dec 2017, 00:15

teadrinker wrote:
teadrinker wrote:
Exaskryz wrote:Have you set this command into your auto-execute section?
Yes, SetTitleMatchMode, 2 must be at the beginning of the script.
:lol:
Damn it. Thought it meant something else.
There's only one little thing that it's now bugging me. Is it possible to disable this when I'm typing in the YouTube search box?
Because I can't use the letter F there, nor in the browser address bar.
teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: YouTube Key Remap

22 Dec 2017, 00:36

Is it possible to disable this when I'm typing in the YouTube search box?
I don't think that it is possible. AHK can't recognize, which element of Opera window is active.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: YouTube Key Remap

22 Dec 2017, 00:39

Hmm, good point that that is now affecting the youtube search box... And you can't use Ctrl+F on the page. Here's one suggestion:

Code: Select all

f::Send {F11}
This makes it a hotkey rather than a remap. So if you got into the habit of typing your search queries in all caps (holding shift), or at least always capitalize f, it would be fine.

But what I think you might be better interested in is doing a toggle. This is code I use for being able to type youtube comments (because on my browser, the video captures regular space keys and pauses/plays the video) that I toggle on and off.

Code: Select all

!space::
Hotkey, space, spaceYT, % (toggle:=!toggle)?"On":"Off"
Tooltip, % (toggle)?"On":""
return

spaceYT:
Send +{Space}
;Tooltip triggered
return  
I use the Tooltip to remind myself I'm typing in the special mode where pressing Space (as defined in the hotkey) results in Shift+Space as output. But you might be more familiar by using a toggle with a flag variable, as demonstrated in (Note: The first link is from the old forums, the second link is on these forums) http://www.autohotkey.com/board/topic/6 ... re-thread/ or https://autohotkey.com/boards/viewtopic.php?f=7&t=11952

Code: Select all

F1::flag:=!flag ; changes flag from true to false; flag can be almost any name you want, it's not a special variable

#If WinActive("YouTube") && flag ; change the WinActive line to whichever works for you with suggestions from earlier in the thread
f::F11 ; or you can do f::Send {F11}

#If ; resets context sensitivity for all hotkeys below this. The bottom most #If also affects hotkeys at the top of the script, it has a "Wrap around" behavior.
; In this script alone, this is necessary for the F1 hotkey to be active at all times. Or a #If can be explicitly placed at the top of the script if that is more clear for you.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], oldbrother, ShatterCoder, Skrell and 139 guests