Jump to content
Sign in to follow this  
Vegar

Countclick help..

Recommended Posts

Vegar

Hello..

i need some help with my script...

it is counting clicks (abc...) and the counting part works but i want to make it to sort the "Guictrlcreatelabel"s in the order of witch letter is the most clicked on....

#include <GuiConstants.au3>
#include <misc.au3>

GUICreate ("ABC",300,300)

Opt("GUIOnEventMode", 1)

GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")

GUICtrlCreateLabel ("Click on A, B or C",120,20,400,50)
$A_click = GUICtrlCreateLabel("A Clicks = 0", 51, 40, 400, 50)
$B_click = GUICtrlCreateLabel("B Clicks = 0", 51, 70, 400, 50)
$C_click = GUICtrlCreateLabel("C Clicks = 0", 51, 100, 400, 50)

GUISetState ()

$clicksA  = 0
$clicksB  = 0
$clicksC  = 0

while 1

If _IsPressed("41", "user32.dll") Then
    while _IsPressed("41","user32.dll")
        sleep(1)
        WEnd
    $clicksA = $clicksA + 1
    GUICtrlSetData($A_click, "A Clicks = " & $clicksA)
EndIf


If _IsPressed("42", "user32.dll") Then
    while _IsPressed("42","user32.dll")
        sleep(1)
        WEnd
    $clicksB = $clicksB + 1
    GUICtrlSetData($B_click, "B Clicks = " & $clicksB)
EndIf

If _IsPressed("43", "user32.dll") Then
    while _IsPressed("43","user32.dll")
        sleep(1)
        WEnd
    $clicksC = $clicksC + 1
    GUICtrlSetData($C_click, "C Clicks = " & $clicksC)
EndIf
WEnd

func _exit ()
    Exit
EndFunc

so if "B" is the most clicked button i want that to be on the top.. and if "C" is second i want it to be listed as second and so on and so on...

Edited by Vegar

Share this post


Link to post
Share on other sites
martin

Hello..

i need some help with my script...

it is counting clicks (abc...) and the counting part works but i want to make it to sort the "Guictrlcreatelabel"s in the order of witch letter is the most clicked on....

#include <GuiConstants.au3>
#include <misc.au3>

GUICreate ("ABC",300,300)

Opt("GUIOnEventMode", 1)

GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")

GUICtrlCreateLabel ("Click on A, B or C",120,20,400,50)
$A_click = GUICtrlCreateLabel("A Clicks = 0", 51, 40, 400, 50)
$B_click = GUICtrlCreateLabel("B Clicks = 0", 51, 70, 400, 50)
$C_click = GUICtrlCreateLabel("C Clicks = 0", 51, 100, 400, 50)

GUISetState ()

$clicksA  = 0
$clicksB  = 0
$clicksC  = 0

while 1

If _IsPressed("41", "user32.dll") Then
    while _IsPressed("41","user32.dll")
        sleep(1)
        WEnd
    $clicksA = $clicksA + 1
    GUICtrlSetData($A_click, "A Clicks = " & $clicksA)
EndIf


If _IsPressed("42", "user32.dll") Then
    while _IsPressed("42","user32.dll")
        sleep(1)
        WEnd
    $clicksB = $clicksB + 1
    GUICtrlSetData($B_click, "B Clicks = " & $clicksB)
EndIf

If _IsPressed("43", "user32.dll") Then
    while _IsPressed("43","user32.dll")
        sleep(1)
        WEnd
    $clicksC = $clicksC + 1
    GUICtrlSetData($C_click, "C Clicks = " & $clicksC)
EndIf
WEnd

func _exit ()
    Exit
EndFunc

so if "B" is the most clicked button i want that to be on the top.. and if "C" is second i want it to be listed as second and so on and so on...

You could do something like this.

#include <GuiConstants.au3>
#include <misc.au3>

#include <array.au3>

$gui1 = GUICreate("ABC", 300, 300)

Opt("GUIOnEventMode", 1)
Dim $lab[3][3]
Dim $count[3] = [0, 0, 0]
GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")

GUICtrlCreateLabel("Press A, B or C", 120, 20, 400, 20)
For $n = 0 To 2
    $lab[$n][1] = GUICtrlCreateLabel(Chr(Asc("A") + $n) & " Presses = 0", 51, 40 + $n * 30, 400, 50)
    $lab[$n][2] = $n
    $lab[$n][0] = 2 * $n
Next

GUISetState()


While 1
    For $n = 0 To 2
        If _IsPressed(String(41 + $n), "user32.dll") Then
            While _IsPressed(String(41 + $n), "user32.dll")
                Sleep(1)
            WEnd
            $count[$n] += 1
            setlabs()
        EndIf
    Next
    
    
    Sleep(80)
WEnd

Func setlabs()
    For $n = 0 To 2
        $lab[$n][0] = $count[$lab[$n][2]]
        $labtext = Chr(Asc("A") + Number($lab[$n][2])) & " Clicks = " & String($lab[$n][0])
        GUICtrlSetData($lab[$n][1], $labtext)
        ConsoleWrite("text = " & $labtext & @CRLF)
        
        
    Next
    
    _ArraySort($lab, 1)

    For $n = 0 To 2
        ControlMove($gui1, "", $lab[$n][1], -300, 40 + $n * 30, 400, 20)
    Next;doesn't work but if you move twice then it does!!!
    For $n = 0 To 2
        ControlMove($gui1, "", $lab[$n][1], 51, 40 + $n * 30, 400, 20)
    Next
    
EndFunc ;==>setlabs

Func _exit()
    Exit
EndFunc ;==>_exit

Funny problem with ControlMove that I don't understand. After changing the text of the label you have to move twice to get the label displayed where it should be. :)

EDIT: I forgot to mention that there is a 'fault' with _ArraySort IMO becuase it swaps elements with equal values everytime it sorts. so it needs a bit more code to stop that.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Vegar

wow.. verry nice work..

but this was a litle bit to advanced for me to understand...

so could you trie to explaine to me basicaly how it works,and tell me what to do to make just the same just with manny more buttons (up to the hole keyboard)

or

so could you make the script just with many more buttons :)

that would be superb :o

Share this post


Link to post
Share on other sites
martin

wow.. verry nice work..

but this was a litle bit to advanced for me to understand...

so could you trie to explaine to me basicaly how it works,and tell me what to do to make just the same just with manny more buttons (up to the hole keyboard)

or

so could you make the script just with many more buttons :)

that would be superb :o

Well ok but you must try to underrstand it. One advantage of using arrays is that it makes it easy to make changes like that. It also keeps the script shorter.

But I'll make it so that it uses OnEvent for label clicks instead of key presses.

#include <GuiConstants.au3>
#include <misc.au3>
#include <staticconstants.au3>
#include <array.au3>

$last = 25;the number of keys after A
$gui1 = GUICreate("ABC", 300, 300 +30 * ($last - 7))
Opt("GUIOnEventMode", 1)
Dim $lab[$last + 1][3]
GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")

For $n = 0 To $last
    $lab[$n][1] = GUICtrlCreateLabel(Chr(Asc("A") + $n) & " Clicks = 0", 51, 40 + $n * 30, 400, 20);20 was 50 but we don't want overlapping labels!
    GUICtrlSetOnEvent(-1, "labclick")
    $lab[$n][2] = chr(Asc("A") + $n);the letter
    $lab[$n][0] = 0;the count
Next

GUISetState()


While 1
    
    Sleep(80)
WEnd

Func labclick()
    ConsoleWrite("lab clicked" & @CRLF)
    For $n = 0 To $last
        If @GUI_CtrlId = $lab[$n][1] Then
            $lab[$n][0] += 1
            ExitLoop
        EndIf
        
    Next
    setlabs()
EndFunc ;==>labclick


Func setlabs()
    For $n = 0 To $last
        $labtext = $lab[$n][2] & " Clicks = " & String($lab[$n][0])
        GUICtrlSetData($lab[$n][1], $labtext)
    Next
    
    _ArraySort($lab, 1)

    For $n = 0 To $last
        GUICtrlSetState($lab[$n][1], $GUI_HIDE)
        ControlMove($gui1, "", $lab[$n][1], 51, 40 + $n * 30, 400, 20)
        GUICtrlSetState($lab[$n][1], $GUI_SHOW)
    Next
    
EndFunc ;==>setlabs

Func _exit()
    Exit
EndFunc ;==>_exit

The basic idea is that you use an array. 3 columns and as many rows as there are labels. The first column is for the count. The second col is the label id. The letter for the label.

First we create the labels, set the count to 0, put the id in col 1 and the label letter in col 2.

When a label is clicked we loop through the labels until we find the labe which has the same id as the item which created the event (@GUI_CtrlId). Then we increment the count for that row, exit the loop because we have found the label, and then redisplay the labels in order.

If you're not used to dealing with arrays I know it can be very confusing, and having me explain it probably doesn't help, especially since I wish I'd gone to bed an hour ago.

Anyway, try to figure it out.

EDIT: changed so that _IsPressed not used and counts the clicks on the labels.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Vegar

:) hmm, still to complicated :S

but is there any way to make the same thing just easyer to understand... (even doh its more work to write down... )

i tried to change the labelclick over to the buttons again but did not get it to work, (dont know why it would not work :S )

Sorry kind of a noob :S

but very thankfull for help :lmao:

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  

×