How can I determine whether the menu bar is currently activated by Alt key? (/ if Alt key is toggled?)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
NorInd
Posts: 43
Joined: 03 May 2020, 04:23

How can I determine whether the menu bar is currently activated by Alt key? (/ if Alt key is toggled?)

29 Aug 2022, 17:34

In most of the software,
If you press alt, its now in a toggled ON state.
If you press alt again, its now in a toggled OFF state.

How can I detect that in AHK?

<see Update 20220901 [How can I determine whether the menu bar is currently activated by Alt key?]>

---
note: ie: I want something analogous to use GetKeyState to get the toggle state of CapsLock, NumLock and ScrollLock,
but alt is not really a "toggleable key" from that aspect.

(note: This topic is not meant to detect "holding down" the alt key.)

----
Testing code to check GetKeyState on Alt (but not what I want)

#### Update 20220901
How to detect if Alt key is toggled?
>>
How can I determine whether the menu bar is currently activated by Alt key? (/ if Alt key is toggled?)
Last edited by NorInd on 31 Aug 2022, 13:18, edited 3 times in total.
lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: How to detect if Alt key is toggled?

30 Aug 2022, 03:45

NorInd wrote:
29 Aug 2022, 17:34
In most of the software,
If you press alt, its now in a toggled ON state.
If you press alt again, its now in a toggled OFF state.
No.
note: ie: I want something analogous to use GetKeyState to get the toggle state of CapsLock, NumLock and ScrollLock,
but alt is not really a "toggleable key" from that aspect.
Exactly. Alt is not toggled. It just triggers (or might trigger) a change of state in the application.

What do you actually want to achieve?

In most programs, pressing Alt activates the menu bar. You might want to determine whether the menu bar is active because if it is, any sent keys will affect the menus, not the focused control. There are other ways to activate the menu bar, so you don't really want to know whether Alt is toggled. Defining the problem or goal correctly is important to finding a solution - or getting help, if others can't guess what your goal is.

If Alt does something else "toggle-like" in some other program, that's likely to be completely different, and need different methods to detect. There would also obviously be different reasons for detecting it in the first place.
RussF
Posts: 1311
Joined: 05 Aug 2021, 06:36

Re: How to detect if Alt key is toggled?

30 Aug 2022, 06:38

Perhaps @NorInd has Sticky Keys enabled without realizing it?

Russ
NorInd
Posts: 43
Joined: 03 May 2020, 04:23

Re: How to detect if Alt key is toggled?

31 Aug 2022, 13:12


## Problem (Clarification)
lexikos wrote:
30 Aug 2022, 03:45
In most programs, pressing Alt activates the menu bar. You might want to determine whether the menu bar is active
Yes, I meant to say: "activates the menu bar"; not "any real toggle" of alt (-- it just behaves similar to a toggle state (I couldnt find the right term to describe)).

So, my problem is:
How can I determine whether the menu bar is currently activated by Alt key?

---
RussF wrote:
30 Aug 2022, 06:38
Perhaps @NorInd has Sticky Keys enabled without realizing it?
(So, the answer to this is also No.)
lexikos wrote:
30 Aug 2022, 03:45
If Alt does something else "toggle-like" in some other program
(So, no, as clarified above, the behaviour is not specific to any application.)
lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: How to detect if Alt key is toggled?

01 Sep 2022, 06:13

NorInd wrote:
31 Aug 2022, 13:12
So, my problem is:
How can I determine whether the menu bar is currently activated by Alt key?
I think you are still not defining your actual problem. For example, this is a problem:
I wrote:You might want to determine whether the menu bar is active because if it is, any sent keys will affect the menus, not the focused control.
If the purpose is to automate one specific action in one specific program, and the problem is that sent keys sometimes have the wrong effect because a menu bar is active, there are likely multiple solutions. Some of those solutions might not involve the menu bar or Alt key at all.

In other words, I think that this is a case of the XY problem.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, emp00 and 171 guests