Jump to content

Run a function as long as X key is pressed


Its2l82die
 Share

Recommended Posts

Hi guys,

My problem is a script which I don't really know how to write.

I want to have a HotKeySet type of function that will run the function only when the key is pressed and when I let it go it will stop(using some kind of loop inside of course),

rather than press key X and the function is running until X is pressed again, like so:

HotKeySet("{1}","Single")
Func Single ()
    $1 = Not $1
EndFunc

While 1
    While $1
        ControlSend($hwnd,"","","{F2}")
        Sleep(200)
        ControlSend($hwnd,"","","{F4}")
    WEnd
WEnd

And make the function be in a certain sleep mode if its possible(not the old "while 1 sleep(x) wend" type of thing), cause I cant be wasting valuable RAM resources.

Thanks in advance,

Its2l82die

EDIT: Found my answer using {X Down} please close of delete this thread there is no more use in it, and sorry for opening it.

Edited by Its2l82die
Link to comment
Share on other sites

Hi guys,

My problem is a script which I don't really know how to write.

I want to have a HotKeySet type of function that will run the function only when the key is pressed and when I let it go it will stop(using some kind of loop inside of course),

rather than press key X and the function is running until X is pressed again, like so:

HotKeySet("{1}","Single")
Func Single ()
    $1 = Not $1
EndFunc

While 1
    While $1
        ControlSend($hwnd,"","","{F2}")
        Sleep(200)
        ControlSend($hwnd,"","","{F4}")
    WEnd
WEnd

And make the function be in a certain sleep mode if its possible(not the old "while 1 sleep(x) wend" type of thing), cause I cant be wasting valuable RAM resources.

Thanks in advance,

Its2l82die

EDIT: Found my answer using {X Down} please close of delete this thread there is no more use in it, and sorry for opening it.

You may also want to try the _IsPressed() function. Every key has a numerical value for use with the function. You can find the number for every key in the help file for the function.

You could do something like this:

While _IsPressed(55)
;DO SOME STUFF WHILE KEY IS PRESSED
WEnd

Loop begins when the key is pressed and loops until the key is released.

Edited by jebus495
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...