Media Next and Home Key Win 11

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ejbones
Posts: 7
Joined: 29 Sep 2022, 13:27

Media Next and Home Key Win 11

Post by ejbones » 29 Sep 2022, 13:31

Hey all,
I had this code working for windows 10, but after upgrading to Windows 11, I'm getting the error
Error at Line 10.
Line Text: Media_Prev} :: Send {Home}
Error: Invalid hotkey.
Hopefully this is something simple and syntax related; not compatibility? It's a Lenovo Yoga c940-15 laptop.

Thanks for any pointers

User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Media Next and Home Key Win 11

Post by boiler » 29 Sep 2022, 14:29

If that’s really reflecting the code, I don’t think it would have worked on Windows 10 either. Looks like you have a stray brace before the ::

ejbones
Posts: 7
Joined: 29 Sep 2022, 13:27

Re: Media Next and Home Key Win 11

Post by ejbones » 29 Sep 2022, 21:17

Forgot the code snippet:

Code: Select all

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

^q:: ; ctrl q will send alt-f4
Send !{f4}
return

{Media_Prev} :: Send {Home}
return

{Media_Next}:: Send {End}
return
[Mod edit: Changed quote tags to [code][/code] tags.]

User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Media Next and Home Key Win 11

Post by boiler » 29 Sep 2022, 21:34

OK, so you didn’t have one stray brace. You had two. You don’t put braces around the key name for a hotkey label. Again, that wouldn’t have worked on Windows 10 either.

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Media Next and Home Key Win 11

Post by lexikos » 29 Sep 2022, 21:37

Also:

There must not be a space between the key name and ::.

When you place a command on the same line as the hotkey label, it becomes a single-line hotkey. A return is implied after the hotkey's action (Send), so the return you have in the code above does nothing.

Code: Select all

Media_Prev:: Send {Home}
Media_Next:: Send {End}

ejbones
Posts: 7
Joined: 29 Sep 2022, 13:27

Re: Media Next and Home Key Win 11

Post by ejbones » 30 Sep 2022, 11:36

Thank you all. So do I not need a return at all?

See working script

Code: Select all

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

^q:: Send !{f4}; ctrl q will send alt-f4

Media_Prev:: Send {Home}

Media_Next:: Send {End}
[Mod edit: [code][/code] tags added, quote tags were replaced.]

gregster
Posts: 9001
Joined: 30 Sep 2013, 06:48

Re: Media Next and Home Key Win 11

Post by gregster » 30 Sep 2022, 11:41

@ejbones: Please use code tags instead of quote tags, when posting code.
In the full editor, it's the fifth button from the left (eitner labeled 'code' or '</>'). Thank you!

User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Media Next and Home Key Win 11

Post by boiler » 30 Sep 2022, 12:42

ejbones wrote: So do I not need a return at all?
Not for single-line hotkeys, as lexikos pointed out.

ejbones
Posts: 7
Joined: 29 Sep 2022, 13:27

Re: Media Next and Home Key Win 11

Post by ejbones » 30 Sep 2022, 15:09

Thanks for helping a newbie out all :thumbup:

Post Reply

Return to “Ask for Help (v1)”