How to press "ALT+F4" using AutoIt

11,954

Solution 1

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.

Solution 2

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)
Share:
11,954
Ripon Al Wasim
Author by

Ripon Al Wasim

[email protected] skype: ripon_sky

Updated on June 04, 2022

Comments

  • Ripon Al Wasim
    Ripon Al Wasim almost 2 years

    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?

  • AdamMc331
    AdamMc331 almost 9 years
    I would like to add that this link has a list of all keys you can send, which will help put together the required combination: autoitscript.com/autoit3/docs/appendix/SendKeys.htm
  • Ripon Al Wasim
    Ripon Al Wasim almost 9 years
    Thanks McAdam331 for providing the good link.
  • Ripon Al Wasim
    Ripon Al Wasim almost 9 years
    @anAgent: Many thanks for your helpful answer.