Jump to content

Recieving User Input


abysmal
 Share

Recommended Posts

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

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

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

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

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

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
Link to comment
Share on other sites

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
Link to comment
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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...