Just "press"Alt to activate a toolbar Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Fleco
Posts: 7
Joined: 30 Dec 2020, 18:43

Just "press"Alt to activate a toolbar

Post by Fleco » 30 Dec 2020, 18:56

Hi,
I would like to open the notepad and then press "Alt" to activate the toolbar.
After that, I am going to send a couple of letters to choose to "Save as" and write a file name.
However, I could not find how to simply "press" Alt using AutoHotkey script.

Here is my code

Code: Select all

#n::
Run Notepad
Send This is what I want to write ...  
Send {Alt}; Is this line wrong?
Send F
Send A
Send file_name.txt {enter}
Sleep %2%000  ; Sleep for 2 seconds.
return
[Mod edit: [code][/code] tags added.]

Cheers
Last edited by Fleco on 31 Dec 2020, 12:53, edited 1 time in total.

User avatar
mikeyww
Posts: 27274
Joined: 09 Sep 2014, 18:38

Re: Just "press"Alt to activate a toolbar  Topic is solved

Post by mikeyww » 30 Dec 2020, 19:52

Code: Select all

proc := "notepad.exe", wTitle := "ahk_exe " proc

#n::
If WinExist(wTitle)
 WinActivate
Else Run, %A_WinDir%\System32\%proc%
WinWaitActive, %wTitle%,, 5
If ErrorLevel {
 MsgBox, 48, Error, An error occurred while waiting for the window.
 Return
}
Send !fa
WinWaitActive, Save As ahk_class #32770 %wTitle%,, 10
If ErrorLevel
 MsgBox, 48, Error, An error occurred while waiting for the window.
Else SendInput file_name.txt{Enter}
Return

Fleco
Posts: 7
Joined: 30 Dec 2020, 18:43

Re: Just "press"Alt to activate a toolbar

Post by Fleco » 31 Dec 2020, 12:10

Thanks so much for this piece of very well written code!
There is still something that I can not figure out.
When I must use Alt and when !?,
For instance, if instead of Alt I would press F1 or cursor down, what should I put instead of !?
Cheers
Dario

User avatar
mikeyww
Posts: 27274
Joined: 09 Sep 2014, 18:38

Re: Just "press"Alt to activate a toolbar

Post by mikeyww » 31 Dec 2020, 12:21

I assumed that you wanted to activate the "Save as" menu option, so that is why I indicated "ALT-F-A" or !fa for short. Incidentally, AHK also has a WinMenuSelectItem command.

Code: Select all

WinMenuSelectItem, %wTitle%,, File, Save As
! is a modifier of the next key that follows it. :arrow: Send

You could issue {Alt Down}, {Alt Up}, etc., but it is not necessary in this case. Since you are modifying a single key, you can use !, and AHK will handle the down and up part for you.

Here is a list of keys in case helpful.

Fleco
Posts: 7
Joined: 30 Dec 2020, 18:43

Re: Just "press"Alt to activate a toolbar

Post by Fleco » 31 Dec 2020, 12:50

Thanks for your prompt answer!
Yes, I wanted to activate the "Save as" menu option and your code makes that job perfectly.
I was wonder how it changes if instead of Alt I need to press F1.
Looking at the help for "Send" command you share with me I see that I must use Send {F1} in that case.
So that, the problem in my first horrible code was not the line I thought, namely: Send {Alt}. That's fine.
My original problem was, essentially, not including the "WinWaitActive,,, 5" line, right?
Thanks one more time!

User avatar
mikeyww
Posts: 27274
Joined: 09 Sep 2014, 18:38

Re: Just "press"Alt to activate a toolbar

Post by mikeyww » 31 Dec 2020, 13:44

Yes, you can Send {F1} if needed. The Send command sends keys to the active window.

You are mostly correct: if you Run a program, the script continues to the next command immediately, without waiting for the program window to become active. If the next command is Send, then the keys will typically be sent to the wrong window.

When you send a key by itself-- such as Alt-- AHK will press and release the key. It so happens that if you press and release Alt in many programs, such as Notepad, the menu will remain activated so that you can then continue to use the keyboard to activate menu items via keyboard shortcuts.

Although WinMenuSelectItem works only in programs with standard Windows-style menus, it may be more reliable than an Alt sequence in such cases.

CAMman
Posts: 1
Joined: 15 Sep 2022, 05:33

Re: Just "press"Alt to activate a toolbar

Post by CAMman » 15 Sep 2022, 05:53

Hi,

I can't get the toolbar to activate just with a send Alt code.

Code: Select all

^l::
Send !
Return
Please help

Thank you

User avatar
mikeyww
Posts: 27274
Joined: 09 Sep 2014, 18:38

Re: Just "press"Alt to activate a toolbar

Post by mikeyww » 15 Sep 2022, 07:37

Perhaps:

Code: Select all

^l Up::
KeyWait, Ctrl
Send {Alt}
SoundBeep, 1500
Return

Post Reply

Return to “Ask for Help (v1)”