Jump to content

Check if any of X keys is pressed using _IsPressed()

Recommended Posts



I'm new to AutoIt but loving it so far. I have a script that is running, and while running I'm looking for if any of the following keys is pressed to stop run: ESC, Tab or Enter. The script looks something like this:

#include <Misc.au3>

Const $user32 = DllOpen("user32.dll")

Local $StopKeys = ["0D", "09", "1B"] ; Keys to look for and exit: Enter, TAB & ESC keys

While True
    For $key in $StopKeys ; Iterate through each key in $StopKeys
        If _IsPressed($key, $user32) Then ; Check if any of them are pressed
            While _IsPressed($key, $user32) ; Wait for release

            Exit ; Exit

I was just wondering if this is the best way to accomplish this. Is there another approach to this that I'm missing?


Share this post

Link to post
Share on other sites

Wrote something similar last week which may help.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now