Sign in to follow this  
Followers 0
DragonBall

detect doublce click

4 posts in this topic

I am trying to write a script which detect double click, so I use the following example to learn how to do it.

#include <Misc.au3>
#include <Math.au3>
#include <Timers.au3>
$dll = DllOpen("user32.dll")
While 1
    If _isPressed("1", $dll) Then

     Local $LeftMouseClickTime = _Timer_Init()
        While Not _isPressed("1", $dll)
            ToolTip(_Timer_Diff($LeftMouseClickTime))
  WEnd
    EndIf
WEnd
DllClose($dll)

The problem is that when I click the mouse, it starts to count the time. But when I click the mouse second time, sometime the count is finished. But sometimes it starts a new count. I think the problem is because it pass the value of _isPressed("1", $dll) to the line If... just below While 1. I have tried to add Sleep(200) like the following:

#include <Misc.au3>
#include <Math.au3>
#include <Timers.au3>
$dll = DllOpen("user32.dll")
While 1
    If _isPressed("1", $dll) Then

     Local $LeftMouseClickTime = _Timer_Init()
        While Not _isPressed("1", $dll)
            ToolTip(_Timer_Diff($LeftMouseClickTime))
  WEnd
    EndIf
Sleep(200)
WEnd
DllClose($dll)

The script is running , but there is no count appear now. I can't figure out why....

Share this post


Link to post
Share on other sites



Tell us what you want to do instead of what you're doing and we can probably suggest something better. This is just... Bleh.

And why are you using the UDF timers when we have TimerInit()/TimerDiff() natively?

Share this post


Link to post
Share on other sites

@AdmiralAlkex:

Because I don't know there is TimerInit...I just found _Timer_Init, thank you to point this. I have mentioned that I would like to have a script which could detect a double (left) mouse click ( and of course when it detect this, do other things.) I thought the above codes will illustrate better what problem I got stuck. There are two places where it tests if _isPressed("1", $dll) and it gets confused.

So I add sleep(200), but it doesn't count anymore....

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Tuned for my clicks, may not work for you...

#include <Misc.au3>

$dll = DllOpen("user32.dll")

check()

Func check()
If _IsPressed("1", $dll) Then
    Sleep (52)
If Not _IsPressed("1", $dll) Then
    Sleep (52)
If _IsPressed("1", $dll) Then
MsgBox(0,"_IsPressed", "Key Pressed")
EndIf
EndIf
EndIf
EndFunc

Do
check()
Until $dll = 0
DllClose($dll)

EDIT: edited timers, to more accurate result go to http://stopwatch.onlineclock.net/

double click normally on start, then divide the time by 3, and write the result on the 2 timers (sleep)

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

 

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