Jump to content

how do i use ispressed to call a function just once


rmkbow
 Share

Recommended Posts

#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

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