Jump to content

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


Recommended Posts

Hello,

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
                Sleep(50)
            WEnd

            Exit ; Exit
        EndIf
    Next
WEnd

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

Thanks

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...