Hotkey Not Working When Using Alt (!) Function

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
asopala
Posts: 21
Joined: 23 May 2021, 13:52

Hotkey Not Working When Using Alt (!) Function

07 Jun 2021, 22:07

Hey all,

Having a very basic issue with my string of code. I'm trying to do something very basic with sending out Alt+NumpadAdd, but it doesn't seem to be registering the Alt key. Doing the same thing with the control key works, but not the alt key. Here's the code that works:

Code: Select all

pgup:: ;Object Grabber extending end of clip
	if WinActive("ahk_class DigiAppWndClass")
		Send ^{NumpadAdd}
	return

pgdn:: ;Object Grabber shortening end of clip
	if WinActive("ahk_class DigiAppWndClass")
		Send ^{NumpadSub}
	return
And here's the code that doesn't. It registers the Numpad keys, but not the Alt Key. On the one I remapped to the insert key, I also get the Windows Error chime with it.

Code: Select all

insert:: ;Object Grabber extending beginning of clip
	if WinActive("ahk_class DigiAppWndClass")
		Send !{NumpadAdd}
	return

delete:: ;Object Grabber shortening beginning of clip
	if WinActive("ahk_class DigiAppWndClass")
		Send !{NumpadSub}
	return
Anybody know what's going on?

BTW, DigiAppWndClass is for the main window in the DAW Pro Tools. Works in every other string, so I've ruled that out.
User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: Hotkey Not Working When Using Alt (!) Function

08 Jun 2021, 06:10

I do not have a way to test it, but Alt can be tricky as it sometimes tries to activate a program's menu. You could try changing the hotkey to the "up" version, such as Insert Up. If you search the forum for "Alt", you might find other approaches. One of the suggestions is to avoid that sequence in these situations! Another option could be {Alt down}xxx{Alt up}, but it may or may not work.
asopala
Posts: 21
Joined: 23 May 2021, 13:52

Re: Hotkey Not Working When Using Alt (!) Function

08 Jun 2021, 15:11

mikeyww wrote:
08 Jun 2021, 06:10
I do not have a way to test it, but Alt can be tricky as it sometimes tries to activate a program's menu. You could try changing the hotkey to the "up" version, such as Insert Up. If you search the forum for "Alt", you might find other approaches. One of the suggestions is to avoid that sequence in these situations! Another option could be {Alt down}xxx{Alt up}, but it may or may not work.
Yeah, that didn't do it. That's very strange that it does that.
asopala
Posts: 21
Joined: 23 May 2021, 13:52

Re: Hotkey Not Working When Using Alt (!) Function

08 Jun 2021, 19:03

Can't seem to find anything on the forum that solves my conundrum. Anyone able to help me figure this out? It works doing it manually (pressing the alt key and keypad + and - keys), but it's just not happening in the script.
jcuendet
Posts: 1
Joined: 10 Jun 2021, 10:30

Re: Hotkey Not Working When Using Alt (!) Function

10 Jun 2021, 11:01

I think this issue is specific to pro tools and the way it hijacks Alt and Win keys.
I've been trying to achieve this for years and I guess the only way would be to trick pro tools into thinking it comes from the physical keyboard since it does work when using it...
asopala
Posts: 21
Joined: 23 May 2021, 13:52

Re: Hotkey Not Working When Using Alt (!) Function

08 Jul 2021, 21:19

jcuendet wrote:
10 Jun 2021, 11:01
I think this issue is specific to pro tools and the way it hijacks Alt and Win keys.
I've been trying to achieve this for years and I guess the only way would be to trick pro tools into thinking it comes from the physical keyboard since it does work when using it...
Which makes me wonder if anyone else has had this issue or has a solution. Anyone got anything?

Separately, any way to test that Alt+NumpadAdd/Sub is being sent? Like something that just says what I just typed or something.
eagerahk
Posts: 122
Joined: 02 Dec 2015, 06:27

Re: Hotkey Not Working When Using Alt (!) Function

08 Jul 2021, 23:33

Code: Select all

!NumpadAdd::
msgbox  !NumpadAdd is just activated
return 
!NumpadSub::
msgbox  !NumpadSub is just activated
return 
asopala
Posts: 21
Joined: 23 May 2021, 13:52

Re: Hotkey Not Working When Using Alt (!) Function

09 Jul 2021, 14:30

eagerahk wrote:
08 Jul 2021, 23:33

Code: Select all

!NumpadAdd::
msgbox  !NumpadAdd is just activated
return 
!NumpadSub::
msgbox  !NumpadSub is just activated
return 
I think I should clarify: any way to know if, for example, pressing the Insert key will send Alt+NumpadAdd? I think it's mostly a Pro Tools issue (as this seems to be a common problem when I looked it up), but for debugging purposes.
lexikos
Posts: 9560
Joined: 30 Sep 2013, 04:07
Contact:

Re: Hotkey Not Working When Using Alt (!) Function

10 Jul 2021, 03:35

With

Code: Select all

insert:: ;Object Grabber extending beginning of clip
	if WinActive("ahk_class DigiAppWndClass")
		Send !{NumpadAdd}
	return
Pressing Insert will send !{NumpadAdd} unless:
  • The hotkey isn't detected or can't execute.
  • The active window's class is not DigiAppWndClass.
Rather than going through all of the conditions that might prevent the hotkey from executing to determine whether the keys will be sent, it is much easier to simply test whether they are sent.

Code: Select all

insert:: ;Object Grabber extending beginning of clip
	if WinActive("ahk_class DigiAppWndClass")
	{
		Send !{NumpadAdd}
		MsgBox !{NumpadAdd} was sent.
	}
	return
Basically, if Send was called, !{NumpadAdd} was sent. So another way is to check ListLines.

Yet another way is to check KeyHistory, which shows both sent keys and pressed keys. It would also show you whether the insert key was recognized as a hotkey.

That it was sent doesn't mean it was received. To know whether it was received even when there are no observable effects, you would have to be at the receiving end.

The most common issue that prevents keys from being received is that the target window is running as administrator, and the script is neither running as administrator nor with UI Access. However, in that case your script would not be sending the keys, because it would not detect the hotkey in the first place.



This pattern:

Code: Select all

x::
	if WinActive("y")
		action
	return
performs the action if y is active, but otherwise prevents x from doing anything. Usually it is preferable to make the hotkey specific to one application, allowing it to perform other functions in other applications. For that you should use #IfWinActive or #If:

Code: Select all

#If WinActive("ahk_class DigiAppWndClass")
; #IfWinActive ahk_class DigiAppWndClass  ; same effect
insert::Send !{NumpadAdd}  ; return can be omitted now
delete::  ; or it can be written like before:
	Send !{NumpadSub}
	return
#If
; subsequent hotkeys are global
asopala
Posts: 21
Joined: 23 May 2021, 13:52

Re: Hotkey Not Working When Using Alt (!) Function

22 Sep 2021, 15:23

lexikos wrote:
10 Jul 2021, 03:35
With

Code: Select all

insert:: ;Object Grabber extending beginning of clip
	if WinActive("ahk_class DigiAppWndClass")
		Send !{NumpadAdd}
	return
Pressing Insert will send !{NumpadAdd} unless:
  • The hotkey isn't detected or can't execute.
  • The active window's class is not DigiAppWndClass.
Rather than going through all of the conditions that might prevent the hotkey from executing to determine whether the keys will be sent, it is much easier to simply test whether they are sent.

Code: Select all

insert:: ;Object Grabber extending beginning of clip
	if WinActive("ahk_class DigiAppWndClass")
	{
		Send !{NumpadAdd}
		MsgBox !{NumpadAdd} was sent.
	}
	return
Basically, if Send was called, !{NumpadAdd} was sent. So another way is to check ListLines.

Yet another way is to check KeyHistory, which shows both sent keys and pressed keys. It would also show you whether the insert key was recognized as a hotkey.

That it was sent doesn't mean it was received. To know whether it was received even when there are no observable effects, you would have to be at the receiving end.

The most common issue that prevents keys from being received is that the target window is running as administrator, and the script is neither running as administrator nor with UI Access. However, in that case your script would not be sending the keys, because it would not detect the hotkey in the first place.



This pattern:

Code: Select all

x::
	if WinActive("y")
		action
	return
performs the action if y is active, but otherwise prevents x from doing anything. Usually it is preferable to make the hotkey specific to one application, allowing it to perform other functions in other applications. For that you should use #IfWinActive or #If:

Code: Select all

#If WinActive("ahk_class DigiAppWndClass")
; #IfWinActive ahk_class DigiAppWndClass  ; same effect
insert::Send !{NumpadAdd}  ; return can be omitted now
delete::  ; or it can be written like before:
	Send !{NumpadSub}
	return
#If
; subsequent hotkeys are global
Going back to this after a few months, it seems that Pro Tools just hijacks alt and windows. Seems there's no way around it if there's actions that require them (and don't exist in the menu options). I now know the keys are being sent, but not received. It stinks, but what can ya do? Unless there's some crazy convoluted way to bypass that "hijacking".
asopala
Posts: 21
Joined: 23 May 2021, 13:52

Re: Hotkey Not Working When Using Alt (!) Function

26 Apr 2022, 20:51

Just replying in case anyone else finds this, Pro Tools now allows you to change key commands, so you can bypass that whole issue. Took long enough.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 203 guests