Sign in to follow this  
Followers 0
rmkbow

how do i use ispressed to call a function just once

4 posts in this topic

How would I go about using ispressed to call a function only once. But after the button is de-pressed, it is immediately available again.

or is this not possible.

Share this post


Link to post
Share on other sites



#include <Misc.au3>
$Dll = DllOpen("user32.dll")
Global $MyFunctionHasBeenRun = False

;some code

If _IsPressed(01, $Dll) Then _MyFunction()  ;left mousae button clicked

Func _MyFunction()
    If $MyFunctionHasBeenRun Then Return    ;skips function if Flag is True
    ;som code
    $MyFunctionHasBeenRun = True    ;sets Flag to True so function will not run again
EndFunc

Share this post


Link to post
Share on other sites

Varian pretty much answered this, but as I made the examples:

Blocking version:

#include <misc.au3>
Global $DLLUser32 = DllOpen("user32.dll")

While 1
    If _IsPressed("01", $DLLUser32) Then _TestFunc()
    ConsoleWrite(".") ;dots indicate the main loop is looping
    Sleep(100)
WEnd

Func _TestFunc()
    ConsoleWrite(@CRLF & "_TestFunc()!" & @CRLF)
    While _IsPressed("01", $DLLUser32)
        Sleep(20)
    WEnd
EndFunc

non-blocking:

#include <misc.au3>
Global $fRun
Global $DLLUser32 = DllOpen("user32.dll")

While 1
    If _IsPressed("01", $DLLUser32) Then
        If $fRun Then
            _TestFunc()
            $fRun = False
        EndIf
    Else
        $fRun = True
    EndIf
    ConsoleWrite(".")  ;dots indicate the main loop is looping
    Sleep(100)
WEnd

Func _TestFunc()
    ConsoleWrite(@CRLF & "_TestFunc()!" & @CRLF)
EndFunc

Share this post


Link to post
Share on other sites

ah, awesome. I didn`t think of implementing it like that. Thanks.

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