Jump to content

Timing a left mouse click


Recommended Posts

I am trying to do the following:

If the left mouse button remains clicked for more than 2 seconds then send some keystrokes. I am having problems with the timing.

What this would do is automatically copy highlighted text to the clipboard...just like in linux.

While 1

If _IsPressed('01') = 1 AND (Left mouse button down for more than 2 seconds) Then Send ("^c")

Sleep (10)

Wend

Can anyone direct me to a solution? Yes I am still a noob after several years of using AutoIt. Thanks.

Link to comment
Share on other sites

I am trying to do the following:

If the left mouse button remains clicked for more than 2 seconds then send some keystrokes. I am having problems with the timing.

What this would do is automatically copy highlighted text to the clipboard...just like in linux.

While 1

If _IsPressed('01') = 1 AND (Left mouse button down for more than 2 seconds) Then Send ("^c")

Sleep (10)

Wend

Can anyone direct me to a solution? Yes I am still a noob after several years of using AutoIt. Thanks.

Take a look at this post for the "is the mouse button pressed" part. For the "more than two seconds", take a look at TimerInit and TimerDiff - set a variable to TimerInit before your while loop, and test TimerDiff > 2000 (milliseconds) in your loop condition.

EDIT: OK, now I re-read your code. Change the "While 1" to be "While _IsPressed('01') and timerDiff($iStartTime) <= 2000", add your TimerInit call before the loop, and after the loop test that TimerDiff($iStartTime) is >= 2000 (to be sure the loop didn't exit because the mouse button was released).

Edited by MisterBates
Link to comment
Share on other sites

#include <misc.au3>

While 1
    If _IsPressed('01') = 1 Then
        Local $timer = TimerInit()
        While _IsPressed('01')
            If TimerDiff($timer) > 2000 Then 
                Send ("^c") 
                ExitLoop
            EndIf
            Sleep(10)
            ToolTip(TimerDiff($timer))
        WEnd
    EndIf
    Sleep (10)
Wend

btw, i like this script :)

Edited by Toady

www.itoady.com

A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding

Link to comment
Share on other sites

#include <misc.au3>

While 1
    If _IsPressed('01') = 1 Then
        Local $timer = TimerInit()
        While _IsPressed('01')
            If TimerDiff($timer) > 2000 Then 
                Send ("^c") 
                ExitLoop
            EndIf
            Sleep(10)
            ToolTip(TimerDiff($timer))
        WEnd
    EndIf
    Sleep (10)
Wend

btw, i like this script :)

Thanks to both of you!! Great stuff.

In real life for this to work I had to make some slight changes with the $timer so that ^c would be sent at the appropriate time. It will still need some tweaking for universal application, though. I wonder if there is a completely different approach to getting the job done. Thanks again.

AutoItSetOption ( "SendKeyDelay", '.01' )

AutoItSetOption ( "WinTitleMatchMode", 2 )

#include <misc.au3>

While 1

If _IsPressed('01') = 1 Then

Local $timer = TimerInit()

While _IsPressed('01')

If TimerDiff($timer) > 500 Then

Sleep(1000)

Send ("^c")

ExitLoop

EndIf

Sleep(10)

ToolTip(TimerDiff($timer))

WEnd

EndIf

Sleep (10)

Wend

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...