Jump to content

Need Example Of Delay


Recommended Posts

Hi there i'm trying to get a simple example of...

if mouse click is longer than 200ms, then do this xxx

So far this is what i have, but when 1 is pressed is basically does an extra click.

so i'm thinking is..

if its only a mouse click ignore Send("1")

and if mouse is held >=200ms then Send("1")

i'm not looking for hand outs, just an example of something similar will be fine. so far i'm unsure exactly what function is needed, and have been unable to find something similar in help/google.

thanx in advance

#include <Misc.au3>
While 1
If _IsPressed(01) Then
Sleep(200)
Send("1")
EndIf
Sleep(5)
WEnd
Link to comment
Share on other sites

After _IsPressed("01") = True you need to wait until _IsPressed("01") = False.

That's according to the help file.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

yes but i'm needing some kindof delay before it checks _ispressed.

for example if i do normal left click, then nothing should happen.

but if i hold left click down then script would run.

TimerInit() shows promise, just researching now for working example for something i can make heads or tails off rofl

Link to comment
Share on other sites

I set the timer to 1000 to better demonstrate what's happening...

#include <Misc.au3>

Global $hDLL_User32 = DllOpen("user32.dll")
Global $iTimer_IsPressed_Mouse, $b_IsPressed_Mouse = False, $iTimer_IsPressed_Mouse_Delay = 1000

While 1

    If _IsPressed("01", $hDLL_User32) Then
        If Not $b_IsPressed_Mouse Then
            If Not $iTimer_IsPressed_Mouse Then $iTimer_IsPressed_Mouse = TimerInit() + 10
            If $iTimer_IsPressed_Mouse And TimerDiff($iTimer_IsPressed_Mouse) > $iTimer_IsPressed_Mouse_Delay Then
                $b_IsPressed_Mouse = True
                ConsoleWrite("Mouse pressed" & @CRLF)
                Send("1")
            EndIf
        EndIf
    Else
        $b_IsPressed_Mouse = False
        $iTimer_IsPressed_Mouse = 0
    EndIf

    If _IsPressed("1B", $hDLL_User32) Then ExitLoop

    Sleep(10)

WEnd

DllClose($hDLL_User32)
Link to comment
Share on other sites

I set the timer to 1000 to better demonstrate what's happening...

#include <Misc.au3>

Global $hDLL_User32 = DllOpen("user32.dll")
Global $iTimer_IsPressed_Mouse, $b_IsPressed_Mouse = False, $iTimer_IsPressed_Mouse_Delay = 1000

While 1

If _IsPressed("01", $hDLL_User32) Then
If Not $b_IsPressed_Mouse Then
If Not $iTimer_IsPressed_Mouse Then $iTimer_IsPressed_Mouse = TimerInit() + 10
If $iTimer_IsPressed_Mouse And TimerDiff($iTimer_IsPressed_Mouse) > $iTimer_IsPressed_Mouse_Delay Then
$b_IsPressed_Mouse = True
ConsoleWrite("Mouse pressed" & @CRLF)
Send("1")
EndIf
EndIf
Else
$b_IsPressed_Mouse = False
$iTimer_IsPressed_Mouse = 0
EndIf

If _IsPressed("1B", $hDLL_User32) Then ExitLoop

Sleep(10)

WEnd

DllClose($hDLL_User32)

this is very close, although i don't rly understand it rofl.

only problem is i need to reclick to repeat the loop.

basically while key is held down it should loop

Sleep(200)

Send("1")

and when mouse is clicked the loop should be ignored.

thank you for that reply, trying to make sense of it now : ) way beyound me at this stage rofl

Link to comment
Share on other sites

#include <Misc.au3>

Global $hDLL_User32 = DllOpen("user32.dll")
Global $iTimer_IsPressed_Mouse, $iTimer_IsPressed_Mouse_Delay = 200

While 1

    If _IsPressed("01", $hDLL_User32) Then
        If Not $iTimer_IsPressed_Mouse Then $iTimer_IsPressed_Mouse = TimerInit() + 10
        If $iTimer_IsPressed_Mouse And TimerDiff($iTimer_IsPressed_Mouse) > $iTimer_IsPressed_Mouse_Delay Then
            ConsoleWrite("Mouse pressed" & @CRLF)
            Send("1")
            $iTimer_IsPressed_Mouse = 0
        EndIf
    EndIf

    If _IsPressed("1B", $hDLL_User32) Then ExitLoop

    Sleep(10)

WEnd

DllClose($hDLL_User32)

Edited by KaFu
Link to comment
Share on other sites

mate thats working perfect, thank you very much.

if its not to much hassle could you tell me in simple man terms what everything is doing.

sorry i know i'm a pain, just trying to understand/learn. still very new to this.

If not, i thank you again and understand completly that i've already took up much of your time

Link to comment
Share on other sites

No problem :), I love these little brain teasers, here's a commented version.

#include <Misc.au3>

Global $hDLL_User32 = DllOpen("user32.dll") ; open DLL only once, makes calls faster
Global $iTimer_IsPressed_Mouse, $iTimer_IsPressed_Mouse_Delay = 200 ; initialize global variables

While 1

    If _IsPressed("01", $hDLL_User32) Then ; if mouse is pressed
        If Not $iTimer_IsPressed_Mouse Then $iTimer_IsPressed_Mouse = TimerInit() + 10 ; if timer is not initialized, then initialize (current timestamp) + 10 (max delay lost due to last sleep(10))
        If $iTimer_IsPressed_Mouse And TimerDiff($iTimer_IsPressed_Mouse) > $iTimer_IsPressed_Mouse_Delay Then ; if timer is initialized and difference is > 200 (global var) then
            ConsoleWrite("Mouse pressed" & @CRLF)
            Send("1")
            $iTimer_IsPressed_Mouse = 0 ; un-initialize timer
        EndIf
    EndIf

    If _IsPressed("1B", $hDLL_User32) Then ExitLoop ; exit on ESC

    Sleep(10)

WEnd

DllClose($hDLL_User32)
Link to comment
Share on other sites

thank you again,

although working, i have noticed something that might provide a little brain teasing for ya : )

single click still plays through the script on first click.

dersired functions should be as follows. (again if to much hassle just ignore me : )

single mouse = single mouse click action (Function like standard mouse click without script)

mouse click held over 200ms = run script.

continued hold of mouse click will loop the script.

Link to comment
Share on other sites

Of course the timer needs to be un-initialized too if mouse is not clicked, had that in the first example but accidentally removed that too :)...

#include <Misc.au3>

Global $hDLL_User32 = DllOpen("user32.dll") ; open DLL only once, makes calls faster
Global $iTimer_IsPressed_Mouse, $iTimer_IsPressed_Mouse_Delay = 200 ; initialize global variables

While 1

    If _IsPressed("01", $hDLL_User32) Then ; if mouse is pressed
        If Not $iTimer_IsPressed_Mouse Then $iTimer_IsPressed_Mouse = TimerInit() + 10 ; if timer is not initialized, then initialize (current timestamp) + 10 (max delay lost due to last sleep(10))
        If $iTimer_IsPressed_Mouse And TimerDiff($iTimer_IsPressed_Mouse) > $iTimer_IsPressed_Mouse_Delay Then ; if timer is initialized and difference is > 200 (global var) then
            ConsoleWrite("Mouse pressed" & @CRLF)
            Send("1")
            $iTimer_IsPressed_Mouse = 0 ; un-initialize timer
        EndIf
    Else
        $iTimer_IsPressed_Mouse = 0 ; un-initialize timer
    EndIf

    If _IsPressed("1B", $hDLL_User32) Then ExitLoop ; exit on ESC

    Sleep(10)

WEnd

DllClose($hDLL_User32)
Link to comment
Share on other sites

working as intended, again thank you.

had been scratching my head on this for last 12 hours, and got nowhere rofl.

#include <Misc.au3>

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("!{PAUSE}", "Terminate")


Global $hDLL_User32 = DllOpen("user32.dll")
Global $iTimer_IsPressed_Mouse, $iTimer_IsPressed_Mouse_Delay = 200

Global $hDLL_User32 = DllOpen("user32.dll") ; open DLL only once, makes calls faster
Global $iTimer_IsPressed_Mouse, $iTimer_IsPressed_Mouse_Delay = 200 ; initialize global variables

While 1

    If _IsPressed("01", $hDLL_User32) Then ; if mouse is pressed
        If Not $iTimer_IsPressed_Mouse Then $iTimer_IsPressed_Mouse = TimerInit() + 10 ; if timer is not initialized, then initialize (current timestamp) + 10 (max delay lost due to last sleep(10))
        If $iTimer_IsPressed_Mouse And TimerDiff($iTimer_IsPressed_Mouse) > $iTimer_IsPressed_Mouse_Delay Then ; if timer is initialized and difference is > 200 (global var) then
            ConsoleWrite("Mouse pressed" & @CRLF)
            Send("1")
            $iTimer_IsPressed_Mouse = 0 ; un-initialize timer
        EndIf
    Else
        $iTimer_IsPressed_Mouse = 0 ; un-initialize timer
    EndIf

    Sleep(10)

WEnd

DllClose($hDLL_User32)


Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is Paused', 1047, 0, "   Warning", 0, 4)
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause
Func Terminate()
    Exit 0
EndFunc   ;==>Terminate
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...