Sign in to follow this  
Followers 0
fmen

Timing a left mouse click

5 posts in this topic

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.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

#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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Hi

But for simulate a CTRL + CLICK LEFT ????

How to make?

Sorry my english but i am italian :">

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