maetthew

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

3 posts in this topic

#1 ·  Posted

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

Share this post


Link to post
Share on other sites



#3 ·  Posted

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