Can you detect a double click?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
cvlr
Newbie
Posts: 18
Joined: Thu Jun 07, 2018 4:40 pm

Can you detect a double click?

Post by cvlr » Tue Oct 02, 2018 5:03 pm

I want to be able to detect a left double click in a given window by title. I can't seem to find that. Thanks

User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Can you detect a double click?

Post by JRL » Tue Oct 02, 2018 7:22 pm

There is no function to do that but here is a sample script that uses Notepad as the double click window.. After starting the script, move the message window and the Notepad window to where you can see both. Then you can watch the results of your double click on Notepad in the message window.

Edit:
Sorry for any confusion. Somehow a space character was introduced on a variable assignment causing the variable to fail so for the last hour this code would not work correctly if downloaded. I believe it is now correct.

Code: Select all

//Press Esc key to exit
OnEvent>key_down,VK27,0,srtQuit
//VK1 captures the left mouse click
OnEvent>key_down,VK1,0,srtClick

//Double click speed in milliseconds
Let>DBLClickSpan=600

//Open notepad
Let>RP_Wait=0
RunProgram>%sys_dir%\Notepad.exe

Let>WindowToClickIn=Notepad
Let>ClickCount=0
Timer>StartTime
Let>Click_%ClickCount%=StartTime

//ClickFlag variable is used to prevent the contents of srtClick subroutine
//from executing perpetually while the left mouse button is held down.
Let>ClickFlag=0

Message

Label>Idle
  Wait>0.01
  If>ClickFlag>0
    Add>ClickFlag,1
    If>ClickFlag>3
      Let>ClickFlag=0
    EndIf
  EndIf
  SetControlText>Macro Scheduler Message,TMemo,1,ClickFlag
Goto>Idle

SRT>srtClick
  If>ClickFlag=0
    GetActiveWindow>vTitle,vWinX,vWinY
    UpperCase>vTitle,vTitle
    UpperCase>WindowToClickIn,WindowToClickIn
    Separate>vTitle,WindowToClickIn,vRes
    If>vRes_Count>1
      Add>ClickCount,1
      Let>LastClick=%ClickCount%-1
      Let>LastTime=Click_%LastClick%
      Timer>Click
      Let>Click_%ClickCount%=Click
      Let>Clicktest=Click_%ClickCount%
      Let>ClickSpeed=%Click%-%LastTime%
      If>{%ClickSpeed%<=%DBLClickSpan%}
        SetControlText>Macro Scheduler Message,TMemo,1,LastClick=%lastclick%%crlf%LastTime=%lasttime%%crlf%Click=%click%%crlf%ClickTest=%clicktest%%crlf%%ClickSpeed%<=%DBLClickSpan%%crlf%Double Click Detected in %vTitle%
        Wait>1
      EndIf
    EndIf
  EndIf
  Let>ClickFlag=1
END>srtClick

SRT>srtQuit
  Exit>0
END>srtQuit

User avatar
Grovkillen
Automation Wizard
Posts: 1009
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Can you detect a double click?

Post by Grovkillen » Tue Oct 02, 2018 7:27 pm

If you detect a single click you can start a timer that is then check when next click is done. If the time is below lets say 500mSec then you have a double click.

EDIT: so JRL suggested this already, sorry!
Let>ME=%Script%

Running: 15.0.24
version history

cvlr
Newbie
Posts: 18
Joined: Thu Jun 07, 2018 4:40 pm

Re: Can you detect a double click?

Post by cvlr » Tue Oct 02, 2018 7:45 pm

Thank you. An interesting solution.

User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Can you detect a double click?

Post by JRL » Tue Oct 02, 2018 8:31 pm

@cvlr,
You're welcome.

@Grovkillen,
No need to be sorry. You summed up the concept succinctly and eloquently. Good job.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts