Can you detect a double click?
Moderators: Dorian (MJT support), JRL
Can you detect a double click?
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
Re: Can you detect a double click?
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.
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
- Grovkillen
- Automation Wizard
- Posts: 1131
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: Can you detect a double click?
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!
EDIT: so JRL suggested this already, sorry!
Re: Can you detect a double click?
Thank you. An interesting solution.
Re: Can you detect a double click?
@cvlr,
You're welcome.
@Grovkillen,
No need to be sorry. You summed up the concept succinctly and eloquently. Good job.
You're welcome.
@Grovkillen,
No need to be sorry. You summed up the concept succinctly and eloquently. Good job.