How to press "ALT+F4" using AutoIt

13k views Asked by At

I am new in AutoIt. I have run the notepad by using the following code in AutoIt:

Run("notepad.exe")

Now I want to quit the application by using "ALT+F4". How to press "ALT+F4" with AutoIt tool?

2

There are 2 answers

2
anAgent On BEST ANSWER

You'll want to check out the documentation for AutoIt - which is pretty good.

The one you're looking for is: https://www.autoitscript.com/autoit3/docs/functions/Send.htm

Keep in mind that you want to make sure that the window is active or that you're targeting the window.

With that, I recommend using this : https://www.autoitscript.com/autoit3/docs/functions/ControlSend.htm

ControlSend() works in a similar way to Send() but it can send key strokes directly to a window/control, rather than just to the active window.

0
Ripon Al Wasim On

The following code for pressing "ALT+F4" should work in AutoIt:

Send("{ALT down}{F4 down}{F4 up}{ALT up}")

OR,

Send("!{F4}")

OR,

Send("!{F4}", 0)