Sign in to follow this  
Followers 0
TheSeeker

Mouse Click Counter

9 posts in this topic

#1 ·  Posted (edited)

This is a very simple but may prove quite useful in counting  things on screen. This program counts the total number of left mouse button clicks. The intention was to make a counter while clicking and counting things on screen. 

TO start click on the start button and to stop, click the middle mouse button...

Possible upgrades and suggestions are welcome

CLickCounter_me.au3

Edited by dipan

"Let me win[color=rgb(68,68,68);font-family:arial, sans-serif;font-size:small;], [/color]but if I cannot[color=rgb(68,68,68);font-family:arial, sans-serif;font-size:small;] win, let me be brave in the attempt"[/color]

Share this post


Link to post
Share on other sites



"clear" and "close" are both counted as clicks; do not clear or close.

OnEventMode?

Share this post


Link to post
Share on other sites

So, you first have to stop the counter by middle clicking and then they will work as intended. I am working to make a stop button separately. Any suggestions?


"Let me win[color=rgb(68,68,68);font-family:arial, sans-serif;font-size:small;], [/color]but if I cannot[color=rgb(68,68,68);font-family:arial, sans-serif;font-size:small;] win, let me be brave in the attempt"[/color]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I'm going to go out on a limb here, as I am by no strech of the imagination, the guy to help with or fix your code.

But here's what I was playing with:

Edit: cleaned-up the 'stumble' in the subtract (of this version; original version didn't have that problem).

Edit2: note to self; finish script, THEN post.

Edit3: I have a clearer understanding of your methods. It was fun to try though....

; From dipan , 16 Jun 2013.
#include <GUIConstantSex.au3>
#include <StaticConstants.au3>
#include "Misc.au3"

Opt("GUIOnEventMode", 1)
Global $clicks

$Form1 = GUICreate("#", 109, 95, 350, 143);Once I changed the size there was no room left for the title.Sorry
GUISetOnEvent($GUI_EVENT_CLOSE, "xIt")

$label1 = GUICtrlCreateLabel("0", 2, 2, 105, 35, $SS_CENTER)
GUICtrlSetFont(-1, 20, 400, 0, "Times New Roman")

$buttonMinus = GUICtrlCreateButton("-", 2, 39, 39, 27)
GUICtrlSetOnEvent($buttonMinus, "subtractOne")
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")

$buttonPlus = GUICtrlCreateButton("+", 68, 39, 39, 27)
;GUICtrlSetOnEvent($buttonPlus, "addOne")
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")

$buttonClear = GUICtrlCreateButton("Clear", 2, 68, 105, 25)
GUICtrlSetOnEvent($buttonClear, "resetToZero")

GUISetState(@SW_SHOW)
WinSetOnTop("#", "", 1)

While 1
    Sleep(10)
    If _IsPressed(01) Then
        addOne()
    EndIf
    While _IsPressed(01)
        Sleep(10)
    WEnd
WEnd

Func xIt()
    Exit
EndFunc   ;==>xIt

Func addOne()
    $clicks += 1
    GUICtrlSetData($label1, $clicks)
EndFunc   ;==>addOne

Func subtractOne()
    $clicks -= 2
    GUICtrlSetData($label1, $clicks)
    $readLabel1 = GUICtrlRead($label1)
    If $readLabel1 < 0 Then
    EndIf
EndFunc   ;==>subtractOne

Func resetToZero()
    $clicks = 0
    GUICtrlSetData($label1, $clicks)
EndFunc   ;==>resetToZero
Edited by lorenkinzel
1 person likes this

Share this post


Link to post
Share on other sites

Yeah. I see. This method is also good. I will try cleaning up the stumble and also add a stop button to pause the counting if the user wants. Thanks for the suggestion and update.


"Let me win[color=rgb(68,68,68);font-family:arial, sans-serif;font-size:small;], [/color]but if I cannot[color=rgb(68,68,68);font-family:arial, sans-serif;font-size:small;] win, let me be brave in the attempt"[/color]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

If you haven't already done so, I managed to fix that ugly little stutter when subtracting.

I set the 'add' to happen when the mouse button is released rather than when pressed.

I better let this one go because this thread has got to be boring the more experienced members to tears.

Here's the damage to your script:

#include <GUIConstantSex.au3>
#include <StaticConstants.au3>
#include "Misc.au3"

Opt("GUIOnEventMode", 1)
Global $clicks, $goodToGo

$Form1 = GUICreate("#", 109, 125, 350, 143)
GUISetOnEvent($GUI_EVENT_CLOSE, "xIt")
$label1 = GUICtrlCreateLabel("0", 2, 2, 105, 35, $SS_CENTER)
GUICtrlSetFont(-1, 20, 400, 0, "Times New Roman")
$buttonMinus = GUICtrlCreateButton("-", 2, 39, 39, 27)
GUICtrlSetOnEvent($buttonMinus, "subtractOne")
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$buttonPlus = GUICtrlCreateButton("+", 68, 39, 39, 27);remains for visual
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$buttonClear = GUICtrlCreateButton("Clear", 2, 68, 105, 25)
GUICtrlSetOnEvent($buttonClear, "resetToZero")
$buttonStart = GUICtrlCreateButton("start", 2, 95, 39, 27)
GUICtrlSetOnEvent($buttonStart, "start")
$buttonStop = GUICtrlCreateButton("stop", 68, 95, 39, 27)
GUICtrlSetOnEvent($buttonStop, "stop")
GUISetState(@SW_SHOW)
WinSetOnTop("#", "", 1)

While 1
    Sleep(10)
    If _IsPressed(01) Then
        _E()
    EndIf
WEnd

Func _E();seandisanti 9-19-10
    While 1
        If _IsPressed("01") And $goodToGo = 1 Then
            While _IsPressed("01")
                Sleep(10)
            WEnd ; make it happen when button is RELEASED
            addOne()
        EndIf
        Sleep(10)
    WEnd
EndFunc   ;==>_E

Func xIt()
    Exit
EndFunc   ;==>xIt

Func start()
    $goodToGo = 1
EndFunc   ;==>start

Func stop()
    While 1
        If $goodToGo = 0 Then
            ExitLoop
        EndIf
        $goodToGo = 0
        $clicks -= 1
        GUICtrlSetData($label1, $clicks)
    WEnd
EndFunc   ;==>stop

Func addOne()
    $clicks += 1
    GUICtrlSetData($label1, $clicks)
EndFunc   ;==>addOne

Func subtractOne()
    If $goodToGo = 1 Then
        $clicks -= 2
    Else
        $clicks -= 1
    EndIf
    GUICtrlSetData($label1, $clicks)
EndFunc   ;==>subtractOne

Func resetToZero()
    If $goodToGo = 1 Then
        $clicks = -1
    Else
        $clicks = 0
    EndIf
    GUICtrlSetData($label1, $clicks)
EndFunc   ;==>resetToZero
Edited by lorenkinzel

Share this post


Link to post
Share on other sites

Great work I must say! I had not managed to sit with it... But turns out you have already resolved all the issues! So, I will also let it end.. This should be the last post of this thread


"Let me win[color=rgb(68,68,68);font-family:arial, sans-serif;font-size:small;], [/color]but if I cannot[color=rgb(68,68,68);font-family:arial, sans-serif;font-size:small;] win, let me be brave in the attempt"[/color]

Share this post


Link to post
Share on other sites

Here is the final program after modifying the GUI and fixing a small problem that once the counter is stopped, the plus button was not working. 

; Clickcounter By Dipan and lorenkinzel


#include <GUIConstantSex.au3>
#include <StaticConstants.au3>
#include "Misc.au3"

Opt("GUIOnEventMode", 1)
Global $clicks, $goodToGo

$Form1 = GUICreate("ClickCounter", 317, 183, 350, 143)
GUISetOnEvent($GUI_EVENT_CLOSE, "xIt")
$label1 = GUICtrlCreateLabel("0", 148, 16, 90, 35)
GUICtrlSetFont(-1, 20, 400, 0, "Times New Roman")
$buttonMinus = GUICtrlCreateButton("-", 16, 80, 49, 33)
GUICtrlSetOnEvent($buttonMinus, "subtractOne")
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$buttonPlus = GUICtrlCreateButton("+", 248, 80, 41, 33);remains for visual
GUICtrlSetOnEvent($buttonPlus, "plusOne")
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$buttonClear = GUICtrlCreateButton("Clear", 24, 144, 105, 25)
GUICtrlSetOnEvent($buttonClear, "resetToZero")
$buttonStart = GUICtrlCreateButton("start",  88, 80, 137, 33)
GUICtrlSetOnEvent($buttonStart, "start")
$buttonStop = GUICtrlCreateButton("stop", 184, 144, 105, 25)
GUICtrlSetOnEvent($buttonStop, "stop")
GUISetState(@SW_SHOW)
WinSetOnTop("ClickCounter", "", 1)

global $ifstop = 0
While 1
    Sleep(10)
    If _IsPressed(01) Then
        _E()
    EndIf
WEnd

Func _E();seandisanti 9-19-10
    While 1
        If _IsPressed("01") And $goodToGo = 1 Then
            While _IsPressed("01")
                Sleep(10)
            WEnd ; make it happen when button is RELEASED
            addOne()
        EndIf
        Sleep(10)
    WEnd
EndFunc   ;==>_E

Func xIt()
    Exit
EndFunc   ;==>xIt

Func start()
    $goodToGo = 1
    $ifstop = 0
EndFunc   ;==>start

Func stop()
    While 1
        If $goodToGo = 0 Then
            ExitLoop
        EndIf
        $goodToGo = 0
        $clicks -= 1
        $ifstop = 1
        GUICtrlSetData($label1, $clicks)
    WEnd
EndFunc   ;==>stop

Func addOne()
    $clicks += 1
    GUICtrlSetData($label1, $clicks)
EndFunc   ;==>addOne

Func subtractOne()
    If $goodToGo = 1 Then
        $clicks -= 2
    Else
        $clicks -= 1
    EndIf
    GUICtrlSetData($label1, $clicks)
EndFunc   ;==>subtractOne

Func resetToZero()
    If $goodToGo = 1 Then
        $clicks = -1
    Else
        $clicks = 0
    EndIf
    GUICtrlSetData($label1, $clicks)
EndFunc   ;==>resetToZero

Func plusOne ()
    if $ifstop = 1 then
        $clicks += 1
    GUICtrlSetData($label1, $clicks)
EndIf
EndFunc

"Let me win[color=rgb(68,68,68);font-family:arial, sans-serif;font-size:small;], [/color]but if I cannot[color=rgb(68,68,68);font-family:arial, sans-serif;font-size:small;] win, let me be brave in the attempt"[/color]

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

 

Here is the final program after modifying the GUI and fixing a small problem that once the counter is stopped, the plus button was not working. 

; Clickcounter By Dipan and lorenkinzel


#include <GUIConstantSex.au3>
#include <StaticConstants.au3>
#include "Misc.au3"

Opt("GUIOnEventMode", 1)
Global $clicks, $goodToGo

$Form1 = GUICreate("ClickCounter", 317, 183, 350, 143)
GUISetOnEvent($GUI_EVENT_CLOSE, "xIt")
$label1 = GUICtrlCreateLabel("0", 148, 16, 90, 35)
GUICtrlSetFont(-1, 20, 400, 0, "Times New Roman")
$buttonMinus = GUICtrlCreateButton("-", 16, 80, 49, 33)
GUICtrlSetOnEvent($buttonMinus, "subtractOne")
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$buttonPlus = GUICtrlCreateButton("+", 248, 80, 41, 33);remains for visual
GUICtrlSetOnEvent($buttonPlus, "plusOne")
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$buttonClear = GUICtrlCreateButton("Clear", 24, 144, 105, 25)
GUICtrlSetOnEvent($buttonClear, "resetToZero")
$buttonStart = GUICtrlCreateButton("start",  88, 80, 137, 33)
GUICtrlSetOnEvent($buttonStart, "start")
$buttonStop = GUICtrlCreateButton("stop", 184, 144, 105, 25)
GUICtrlSetOnEvent($buttonStop, "stop")
GUISetState(@SW_SHOW)
WinSetOnTop("ClickCounter", "", 1)

global $ifstop = 0
While 1
    Sleep(10)
    If _IsPressed(01) Then
        _E()
    EndIf
WEnd

Func _E();seandisanti 9-19-10
    While 1
        If _IsPressed("01") And $goodToGo = 1 Then
            While _IsPressed("01")
                Sleep(10)
            WEnd ; make it happen when button is RELEASED
            addOne()
        EndIf
        Sleep(10)
    WEnd
EndFunc   ;==>_E

Func xIt()
    Exit
EndFunc   ;==>xIt

Func start()
    $goodToGo = 1
    $ifstop = 0
EndFunc   ;==>start

Func stop()
    While 1
        If $goodToGo = 0 Then
            ExitLoop
        EndIf
        $goodToGo = 0
        $clicks -= 1
        $ifstop = 1
        GUICtrlSetData($label1, $clicks)
    WEnd
EndFunc   ;==>stop

Func addOne()
    $clicks += 1
    GUICtrlSetData($label1, $clicks)
EndFunc   ;==>addOne

Func subtractOne()
    If $goodToGo = 1 Then
        $clicks -= 2
    Else
        $clicks -= 1
    EndIf
    GUICtrlSetData($label1, $clicks)
EndFunc   ;==>subtractOne

Func resetToZero()
    If $goodToGo = 1 Then
        $clicks = -1
    Else
        $clicks = 0
    EndIf
    GUICtrlSetData($label1, $clicks)
EndFunc   ;==>resetToZero

Func plusOne ()
    if $ifstop = 1 then
        $clicks += 1
    GUICtrlSetData($label1, $clicks)
EndIf
EndFunc

optimized a bit for you quickly..

; Clickcounter By Dipan and lorenkinzel

Opt("GUIOnEventMode", 1)
Global $clicks, $goodToGo, $ifstop = 1, $GUI_EVENT_CLOSE = -3

$Form1 = GUICreate("ClickCounter", 317, 183, 350, 143)
GUISetOnEvent($GUI_EVENT_CLOSE, "xIt")
$label1 = GUICtrlCreateLabel("0", 148, 16, 90, 35)
GUICtrlSetFont(-1, 20, 400, 0, "Times New Roman")
$buttonMinus = GUICtrlCreateButton("-", 16, 80, 49, 33)
GUICtrlSetOnEvent($buttonMinus, "subtractOne")
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$buttonPlus = GUICtrlCreateButton("+", 248, 80, 41, 33);remains for visual
GUICtrlSetOnEvent($buttonPlus, "plusOne")
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$buttonClear = GUICtrlCreateButton("Clear", 24, 144, 105, 25)
GUICtrlSetOnEvent($buttonClear, "resetToZero")
$buttonStart = GUICtrlCreateButton("start",  88, 80, 137, 33)
GUICtrlSetOnEvent($buttonStart, "start")
$buttonStop = GUICtrlCreateButton("stop", 184, 144, 105, 25)
GUICtrlSetOnEvent($buttonStop, "stop")
GUISetState(@SW_SHOW)
WinSetOnTop("ClickCounter", "", 1)

While 1
    Sleep(10)
    If _IsPressed(01) Then
        _E()
    EndIf
WEnd

Func _E();seandisanti 9-19-10
    If _IsPressed("01") And $goodToGo = 1 Then
        _WaitRelease()
        addOne()
    EndIf
EndFunc   ;==>_E

Func xIt()
    Exit
EndFunc   ;==>xIt

Func start()
    $goodToGo = 1
    $ifstop = 0
EndFunc   ;==>start

Func stop()
        $goodToGo = 0
        $clicks -= 1
        $ifstop = 1
        GUICtrlSetData($label1, $clicks)
EndFunc   ;==>stop

Func addOne()
    $clicks += 1
    GUICtrlSetData($label1, $clicks)
EndFunc   ;==>addOne

Func subtractOne()
    If $goodToGo = 1 Then
        $clicks -= 2
    Else
        $clicks -= 1
    EndIf
    GUICtrlSetData($label1, $clicks)
EndFunc   ;==>subtractOne

Func resetToZero()
    If $goodToGo = 1 Then
        $clicks = -1
    Else
        $clicks = 0
    EndIf
    GUICtrlSetData($label1, $clicks)
EndFunc   ;==>resetToZero

Func plusOne ()
    if $ifstop = 1 then
        $clicks += 1
    GUICtrlSetData($label1, $clicks)
EndIf
EndFunc

Func _WaitRelease()
    While _IsPressed(01)
        Sleep(10)
    WEnd
EndFunc   ;==>_WaitRelease

Func _IsPressed($sHexKey, $vDLL = 'user32.dll')
    Local $a_R = DllCall($vDLL, "int", "GetAsyncKeyState", "int", $sHexKey)
    $Last = $sHexKey
    If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc   ;==>_IsPressed
Edited by ReaImDown

[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]

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