Jump to content

Only run when space held down


Recommended Posts

HotKeySet("{SPACE}","_Run")
while 1

    WEnd
Func _Run()

    ;......something to do here
    MsgBox("","","I ran")
Exit
endfunc

ok space held down.... hmmmm 

#include <Misc.au3>
;HotKeySet("{SPACE}","_Run")
$sHexKey=20


while 1
$pressed=_IsPressed($sHexKey)

if $pressed=1 then
    $timer=TimerInit()
EndIf

while $pressed=1
$pressed=_IsPressed($sHexKey)



if $timer<>0 and $pressed=1 Then
    $diff=TimerDiff($timer)
    if $diff > 1000 Then
        _Run()
        ExitLoop
   elseif $pressed<>1 then 
        exitloop
    Else
        sleep(100)
        EndIf
        EndIf
    WEnd

WEnd





Func _Run()

    ;......something to do here
    MsgBox("","","I ran")
Exit
    EndFunc

 

Edited by markyrocks
duh
Link to comment
Share on other sites

1 hour ago, markyrocks said:
HotKeySet("{SPACE}","_Run")
while 1

    WEnd
Func _Run()

    ;......something to do here
    MsgBox("","","I ran")
Exit
endfunc

ok space held down.... hmmmm 

#include <Misc.au3>
;HotKeySet("{SPACE}","_Run")
$sHexKey=20


while 1
$pressed=_IsPressed($sHexKey)

if $pressed=1 then
    $timer=TimerInit()
EndIf

while $pressed=1
$pressed=_IsPressed($sHexKey)



if $timer<>0 and $pressed=1 Then
    $diff=TimerDiff($timer)
    if $diff > 1000 Then
        _Run()
        ExitLoop
   elseif $pressed<>1 then 
        exitloop
    Else
        sleep(100)
        EndIf
        EndIf
    WEnd

WEnd





Func _Run()

    ;......something to do here
    MsgBox("","","I ran")
Exit
    EndFunc

 

thanks for the reply! Hmmm it starts the script but when i release space the script doesnt stop, any ideas?

Link to comment
Share on other sites

#include <Misc.au3>
Local $hDLL = DllOpen("user32.dll")
While Not _IsPressed("1B",$hDLL) ; esc key to end this demo
    If _IsPressed("20",$hDLL) Then ; space key to whatever
        ToolTip("the time is "&@HOUR&":"&@MIN&":"&@SEC&"."&@MSEC)
        Sleep(10)
        ToolTip("")
    EndIf
WEnd

 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

24 minutes ago, samposs said:

thanks for the reply! Hmmm it starts the script but when i release space the script doesnt stop, any ideas?

its doing that bc its just waiting for the next time that you need to press and hold it to run again... if you want it to end after one press then add and exit in there where it needs to exit

 

edit

what i posted seems to work perfectly.  i actually removed the "exit" from the run function and it works as intended over and over.  So maybe whatever your executing doesn't properly terminate itself at the end, or its not returning to the start of the script.  

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