Jump to content

while a key is down?


Recommended Posts

I'm wondering how I can set up a "while" for when a key is being held down? If not for a while, then something that would allow me to execute some kind of loop while a key is being held down. Right now I know how to send keys, hold down keys with autoit, and set hotkeys to run a function, but not how to do this.

Thanks!

Edited by tsincaat
Link to comment
Share on other sites

For simplistic needs, a function:

#include <Misc.au3>

While 1
    _IsDown("09", "_Do")
    Sleep(500)
WEnd

Func _IsDown($ioKey, $ioFunc)
    While _IsPressed($ioKey)
        Call($ioFunc)
        Sleep(10)
    WEnd
EndFunc

Func _Do()
    ConsoleWrite("Tab is held!" & @CRLF)
EndFunc
Edited by JamesBrooks
Link to comment
Share on other sites

I'm wondering how I can set up a "while" for when a key is being held down? If not for a while, then something that would allow me to execute some kind of loop while a key is being held down. Right now I know how to send keys, hold down keys with autoit, and set hotkeys to run a function, but not how to do this.

Thanks!

_IsPressed function:

#include <Misc.au3>
While 1
    If _IsPressed("41") Then
        TrayTip("TEST","You hold down key A",1)
    Else
        TrayTip("","",1)
    EndIf
    Sleep(10)
WEnd

EDIT: a little too late :P

Edited by Andreik

When the words fail... music speaks.

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...