Jump to content
Sign in to follow this  

_IsPressed If Statements

Recommended Posts


I just started Autoit and think its a great language, but I have come across something I can't figure out.

I try to make the code check if the spacebar is pressed and if it is then send a key after, but then stay running without exiting the program.

Heres the code

#include <Misc.au3>
$dll = DllOpen("user32.dll")

If _IsPressed("20", $dll) Then
        Send("{SPACE 20}")

Share this post

Link to post
Share on other sites

Yes. As the program you want to write basically must keep running till you don't stop it for listening for whenever you press you selected key (spacebar in your example) you have to keep it running till you don't stop it. You do this with a While 1 loop which keeps the program running infinitely. Also always add a sleep to infinite loops because otherwise it will keep running same cicle thousands of times in a few milliseconds.

In your posted code, it checks for the pression of spacebar just 1 time then the programs exits because istructions are ended. So you should press spacebar in the fraction of millisecond that the program runs to see the effect.

Hope it cleared things.

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
Sign in to follow this