omiden Posted June 6, 2010 Share Posted June 6, 2010 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}") EndIf Link to comment Share on other sites More sharing options...
DW1 Posted June 6, 2010 Share Posted June 6, 2010 Place the _IsPressed portion in a infinite While loop: #include <Misc.au3> $dll = DllOpen("user32.dll") $ExitKey = '1B'; ESC While 1 Sleep(10) If _IsPressed("20", $dll) Then Send("{SPACE 20}") If _IsPressed($ExitKey, $dll) Then ExitLoop WEnd DllClose($dll) AutoIt3 Online Help Link to comment Share on other sites More sharing options...
niubbone Posted June 7, 2010 Share Posted June 7, 2010 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now