Disable Alt Menu activation after Alt+Tab+Mouseclick switch between programs

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ByronWillis84
Posts: 17
Joined: 06 Dec 2021, 14:59

Disable Alt Menu activation after Alt+Tab+Mouseclick switch between programs

06 Dec 2021, 15:10

Hello,
Here's what I'm trying to do:
I'm in Program #1 (PDF viewer, SumatraPDF). I hit Alt+Tab. It brings up the thumbnails of all active programs. I click on Microsoft Excel to switch (while continuing to hold Alt key). Excel shows up and then I release the Alt key. This activates the Alt menu shortcuts in Excel. I don't want the alt menu to be activated. I often switch between programs copy / pasting things and I want the focus to remain on the spreadsheet after I release Alt key.

I searched around and found that I was not the only one trying to disable alt menus. I have found some success in being able to disable menu activation if I am already in the program and simply strike and release the alt key. However, none of the below solutions will work in conjunction with the Alt+Tab switch programs with a mouseclick and then release Alt.

FYI I am running Windows 10, latest version of AHK, and Excel 2019 (offline version).

Anyone tackled this problem?

Here's the scripts I've tried...
Option #1:

Code: Select all

~LAlt Up:: return
Option #2:

Code: Select all

Alt::Return ;Disables the key alt when it's pressed alone
Option #3:

Code: Select all

Alt::
KeyWait, Alt
return

LAlt Up::
if (A_PriorKey = "Alt")
    return
return
Option #4:

Code: Select all

LAlt::
sendinput, {LAlt down}
sendinput, {SC0E8 down} ;this is the scan code of an unassigned key. As long as you nor the system never use it for anything else, it can be used in THIS way to cancel the menu acceleration.
;tooltip, Lalt is pressed
KeyWait, LAlt
; That line is important, so that ALT does not continuously fire as you are holding it down.
;tooltip, Lalt was released
return

LAlt up::
sendinput, {LAlt up}
sendinput, {SC0E8 up}
;;;Unlike my 2nd keyboard, this method does not use the scan code as a strict "wrapper."
;;tooltip, 
return


RAlt::
sendinput, {RAlt down}
sendinput, {SC0E8 down}
;;tooltip, Ralt is pressed
KeyWait, RAlt
;;tooltip, Ralt was released
return

RAlt up::
sendinput, {RAlt up}
sendinput, {SC0E8 up}
;;tooltip, 
return
Option #5:

Code: Select all

~LAlt::
Sendinput {Blind}{sc0E9}
KeyWait, LAlt ; this wasit for the key to be RELEASED. So that it doesn't keep spamming SC0E9 (as seen from an AHK window Key history and script info... window.)
Sendinput {Blind}{sc0EA}
return

~RAlt::
Sendinput {Blind}{sc0E9}
KeyWait, RAlt ; so that it doesn't keep spamming SC0E9
Sendinput {Blind}{sc0EA}
return
[Mod edit: [code][/code] tags added.]
Last edited by gregster on 06 Dec 2021, 15:26, edited 1 time in total.
Reason: Please use code tags. Thank you!
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Disable Alt Menu activation after Alt+Tab+Mouseclick switch between programs

06 Dec 2021, 15:47

Four more options:

1. Use Win+Tab.

2.

Code: Select all

!LButton::Return
3.

Code: Select all

!LButton::
Click
on := True
Return
#If on
~Alt Up::
SoundBeep, 1500
Send {Esc}
on := False
Return
#If
4.

Code: Select all

~!Tab::on := True
#If on
~Alt Up::Send % ("{Esc}", on := False)
#If
These are just some ideas. I have not tested them much.
ByronWillis84
Posts: 17
Joined: 06 Dec 2021, 14:59

Re: Disable Alt Menu activation after Alt+Tab+Mouseclick switch between programs

06 Dec 2021, 22:21

mikeyww,
Thank you!
1.) Win+Tab. I use this on occasion if I want larger thumbnails, but it's slow. The other disadvantage is that I often use alt+tab without mouse click to quickly switch between two programs once I've established the correct "two most recent" programs. When you release Win+tab it just stays on the thumbnail screen.
2.) Tried this one. When I hold Alt+tab and left click, nothing happens, my left click is disabled.
3.) Tried it. This seems to work?! Will do more testing.
4.) Tried it. This one seems to work too! Using this one now. Fingers crossed it is stable!
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Disable Alt Menu activation after Alt+Tab+Mouseclick switch between programs

07 Dec 2021, 05:52

OK. The following worked here as well.

Code: Select all

GroupAdd, stopAlt, ahk_class XLMAIN ahk_exe EXCEL.exe
~!Tab::
KeyWait, Alt
Send % WinActive("ahk_group stopAlt") ? "{Esc}" : ""
Return
ByronWillis84
Posts: 17
Joined: 06 Dec 2021, 14:59

Re: Disable Alt Menu activation after Alt+Tab+Mouseclick switch between programs

11 Jan 2022, 18:38

So I have just discovered a little issue with this solution. I use a lightweight image viewer called FastStone (which is great, btw!). To close the viewer, I hit ESC. I often use an OCR (optical character recognition) software on images (think like Snagit or a screen snipping utility) and paste the results into Excel/Word. I have gotten used to using Alt+Tab in conjunction with the mouse which I find to be surprisingly efficient. Unfortunately, every time I switch to FastStone, AHK sends Esc to FastStone and it closes the window. Any thoughts on how to amend the code to handle this case?
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Disable Alt Menu activation after Alt+Tab+Mouseclick switch between programs

11 Jan 2022, 19:05

What is your script? Which FastStone viewer are you using?
ByronWillis84
Posts: 17
Joined: 06 Dec 2021, 14:59

Re: Disable Alt Menu activation after Alt+Tab+Mouseclick switch between programs

12 Jan 2022, 22:59

I'm using this code that you suggested above:

Code: Select all

~!Tab::on := True
#If on
~Alt Up::Send % ("{Esc}", on := False)
#If
I'm using "FastStone Image Viewer" (https://www.faststone.org/FSViewerDetail.htm)
ByronWillis84
Posts: 17
Joined: 06 Dec 2021, 14:59

Re: Disable Alt Menu activation after Alt+Tab+Mouseclick switch between programs

17 Jan 2022, 22:29

OK this is great! I'm using this one now:

Code: Select all

GroupAdd, stopAlt, ahk_class XLMAIN ahk_exe EXCEL.exe
~!Tab::
KeyWait, Alt
Send % WinActive("ahk_group stopAlt") ? "{Esc}" : ""
Return
I have the same issue with the Alt Menu activating on the ribbon with Microsoft Word. Would it be possible to add Word to this script?
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Disable Alt Menu activation after Alt+Tab+Mouseclick switch between programs

18 Jan 2022, 06:48

Running Window Spy shows the WinTitle.

In my testing, I found that KeyWait seems to be ignored when the menu is displayed. The following was more reliable.

Code: Select all

GroupAdd, stopAlt, ahk_class XLMAIN ahk_exe EXCEL.exe
GroupAdd, stopAlt, ahk_class OpusApp ahk_exe WINWORD.EXE
~!Tab::
Sleep, 100
SoundBeep, 800  ; OK to delete this line
WinWaitActive, ahk_group stopAlt,, 4
If ErrorLevel
 Return
Send {Esc}
SoundBeep, 1500 ; OK to delete this line
Return
ByronWillis84
Posts: 17
Joined: 06 Dec 2021, 14:59

Re: Disable Alt Menu activation after Alt+Tab+Mouseclick switch between programs

01 Apr 2022, 00:05

I've been using this (successfully) now for a couple of months, but I have run into a couple of issues.

1.) Copy/pasting between spreadsheets. When I am working with two Excel spreadsheets and I'm copying some information from one to the other, I'm not able to. What is happening is this: when I copy a cell on spreadsheet 1, it creates little "ants" running around the cell's border. If you hit 'Esc', it will cancel the copy command and the ants will disappear. When I alt+tab to the next spreadsheet, the script sends an 'Esc' keystroke which cancels the copy on the original spreadsheet, so the paste command is unsuccessful.
2.) Copy/pasting into an excel spreadsheet. Sometimes I will have a cell with a lot of data in it. I'll paste a bit of text into it, and then keep the cell 'active' when I move away. When I return to the spreadsheet, and 'Esc' command is sent, it reverts the cell to the previous state and cancels any changes. This is particularly a nuisance, because sometimes I'll have cells with a paragraph of text from multiple sources, and halfway through I'll forget about this defect, leave the cell mid-edit, and alt-tab back and it wipes out any changes.

A couple of ideas that I had...
1.) Would it be possible to only send the 'Esc' command if it detects that the alt menu is activated? I did a quick test to see how this might work. I highlighted a cell and copied it (producing the running ants). I went to another window and then returned using alt+tab+mouse click on thumbnail. The alt menu activated. I then hit 'Esc' and the alt menu disappeared, but the cell's ants continued to run around the cell. If I hit 'Esc' twice, then they disappear. My concern was that an 'Esc' command would both cancel the copy/paste operation as well as get out of the alt menu.
2.) Would it be possible to send an 'Esc' command only when you use the mouse click to complete the alt+tab action? This might be a little unpredictable though, because I notice that sometimes when I use mouse click to complete the alt+tab action it doesn't activate the alt menu.
3.) Third option... Is there a way to simply disable alt menu activation in Excel using a registry edit? I know this is outside the scope of AHK, but figured I might throw it in the hat anyway!
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Disable Alt Menu activation after Alt+Tab+Mouseclick switch between programs

01 Apr 2022, 04:40

I'm offline for a few days here, so you're on your own, just with thousands on the forum here! :)

Yes. If needed, you can trap the key sequence by removing tilde. You can then do anything: check the source & target windows, etc. Perhaps you want a "block" if both source & target windows are Excel. If needed, you can also create a hotkey for Alt+LButton.

Good luck!
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Disable Alt Menu activation after Alt+Tab+Mouseclick switch between programs

19 Apr 2022, 18:51

It doesn't sound like you have tested any of the latest ideas. Below is a way to block Alt+Tab in Excel.

Code: Select all

GroupAdd, stopAlt, ahk_class XLMAIN ahk_exe EXCEL.exe
GroupAdd, stopAlt, ahk_class OpusApp ahk_exe WINWORD.EXE
~!Tab::
Sleep, 100
SoundBeep, 800  ; OK to delete this line
WinWaitActive, ahk_group stopAlt,, 4
If ErrorLevel
 Return
Send {Esc}
SoundBeep, 1500 ; OK to delete this line
#IfWinActive ahk_exe EXCEL.exe
!Tab::Return
#IfWinActive
Aside from this, you can do some experimenting. You have the tools and building blocks here-- how to specify windows, wait for windows, & send keys. The rest is just arranging the code in the right order, to execute what you have described.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 251 guests