Sign in to follow this  
Followers 0
abysmal

Recieving User Input

11 posts in this topic

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?

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

so i assign a function to a hotkey?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 .. ? :ph34r:

edit: and what pekster said too, about globalness

:(

Edited by trids

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 by abysmal

Share this post


Link to post
Share on other sites

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() function
  • Putting a sleep command inside any infinate loop
The 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.

Share this post


Link to post
Share on other sites

wow i'm retarded i didn't realize that the changing sign was in a loop... wow...

Share this post


Link to post
Share on other sites

got it workin. I'm so stupid i forgot to change that 1 to a 0 in the if statement.

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  
Followers 0