abysmal Posted August 7, 2004 Share Posted August 7, 2004 This is my first time scripting with autoit and I was wondering if there was a way to recieve user input without having focus. What I want to do is allow the user to hit, say, ctrl+ins (while in a seperate program), and this will activate the script, which will run a loop. Anythime during that loop i want the user to be able to end it by hitting the same combination of buttons. Anyone know how I could do this? Link to comment Share on other sites More sharing options...
pekster Posted August 7, 2004 Share Posted August 7, 2004 RTFM. HotKeySet() Interesting how that comes up when you do a search for "hotkey" 'eh? [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes. Link to comment Share on other sites More sharing options...
abysmal Posted August 7, 2004 Author Share Posted August 7, 2004 so i assign a function to a hotkey? Link to comment Share on other sites More sharing options...
pekster Posted August 7, 2004 Share Posted August 7, 2004 Yup. main() Func main() HotKeySet("^{INS}", "loop") While 1 Sleep(100) WEnd EndFunc Func loop() HotKeySet("^{INS}", "main") While 1 ;your code here WEnd EndFunc [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes. Link to comment Share on other sites More sharing options...
abysmal Posted August 7, 2004 Author Share Posted August 7, 2004 for some reason my Send isn't working right main() $on = 0-1 Func main() HotKeySet("^{INS}", "loop") While 1 If $on > 1 Then Send({ENTER}) WEnd EndFunc Func loop() HotKeySet("^{INS}", "main") While 1 $on = $on * (0-1) WEnd EndFunc Link to comment Share on other sites More sharing options...
pekster Posted August 7, 2004 Share Posted August 7, 2004 for some reason my Send isn't working right <{POST_SNAPBACK}>It needs to be in quotes. Also, you need to make $on global if you wish to use it inside any of your functions. [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes. Link to comment Share on other sites More sharing options...
trids Posted August 7, 2004 Share Posted August 7, 2004 (edited) I think it's cos when you first enter main(), $on hasn't been set yet, so the loop doesn't start and it all just falls through .. ? edit: and what pekster said too, about globalness Edited August 7, 2004 by trids Link to comment Share on other sites More sharing options...
abysmal Posted August 7, 2004 Author Share Posted August 7, 2004 (edited) thanks, i fixed both of those things and it executes just fine. THe only thing that's odd is that the script pauses and doesn't do anything Global $on = 0-1 main() Func main() HotKeySet("^{INS}", "loop") While 1 If $on > 1 Then Send ('{ENTER}') WEnd EndFunc Func loop() HotKeySet("^{INS}", "main") While 1 $on = $on * (0-1) WEnd EndFunc Edited August 7, 2004 by abysmal Link to comment Share on other sites More sharing options...
pekster Posted August 7, 2004 Share Posted August 7, 2004 I don't think you want your loop function to be in a while loop. When you press control+insert the first time, it will begin a loop of changing the sign of $on over and over as fast as your CPU can manage it until you press control+insert again. At that point, it will go back to testing a loop and pressing enter as fast as it can, but only if $on is positive.Two things you need to look at:Your loop() functionPutting a sleep command inside any infinate loopThe sleep is important, because otherwise it will use up all of your CPU trying to calculate the loop as fast as it possably can. You rarely want that. [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes. Link to comment Share on other sites More sharing options...
abysmal Posted August 7, 2004 Author Share Posted August 7, 2004 wow i'm retarded i didn't realize that the changing sign was in a loop... wow... Link to comment Share on other sites More sharing options...
abysmal Posted August 7, 2004 Author Share Posted August 7, 2004 got it workin. I'm so stupid i forgot to change that 1 to a 0 in the if statement. 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