Jump to content

counter based on button pressed


 Share

Recommended Posts

I am trying to create a counter based on if certain control id buttons are pressed in a window. From searching it doesn't look like its possible. Here is my current code but it doesn't provide any results.

#include <GUIConstants.au3>
#include <Misc.au3>

Opt("GUICoordMode", 1)
Opt("WinTitleMatchMode", 1)
WinActivate("Program Name")
WinWaitActive("Program Name")
While 1
    If ControlGetFocus("112") AND _IsPressed(01) Then
    $currentvalue = IniRead ("counter.ini", "counter", "currentcount", "0" ) + 1
Iniwrite ( "counter.ini", "counter", "currentcount", $currentvalue )
EndIf
    If ControlGetFocus("210") AND _IsPressed(01) Then
    $currentvalue = IniRead ("counter.ini", "counter", "currentcount", "0" ) + 1
Iniwrite ( "counter.ini", "counter", "currentcount", $currentvalue )
EndIf
If ControlGetFocus("211") AND _IsPressed(01) Then
    $currentvalue = IniRead ("counter.ini", "counter", "currentcount", "0" ) + 1
Iniwrite ( "counter.ini", "counter", "currentcount", $currentvalue )
EndIf
WEnd

Does anyone know if this is even possible or is there a workaround, or is my code just disfunctional?

Thanks

Link to comment
Share on other sites

You might not be using ControlGetFocus in the correct manner. ControlGetFocus is expecting ("Window Title", "Window Text") as its parameters. You seem to be inputting the ControlID, which is what ControlGetFocus will return.

Try something like this:

$curbut = ControlGetFocus ("Program Name")
If $curbut = 112 AND _IsPressed (01) Then
; Add your .ini increment
EndIf

Edit: There may be a syntax problem with the _IsPressed function too. What you're trying to do is possible, but you should read up in the help file for the proper uses of these functions.

Edited by DoctorX
-DRX
Link to comment
Share on other sites

Thanks DocterX for replying. Although after testing still nothing outputed to my .ini file.

Is ControlGetFocus the right command even if there is no keyboard focus in the window?

Is there a way to focus on what button the mouse is hovering over or clicked?

Thanks

Link to comment
Share on other sites

AFAIK keyboard focus and mouse focus are one in the same.

You might have missed my edit about the _IsPressed function.

There is probably a cleaner way to do what you are trying to do, but the way you have it should work if all of the parameters are corrected.

-DRX
Link to comment
Share on other sites

  • Moderators

HMMMM!!

I tried it many different ways testmeout...

It seems that _IsPressed isn't working for me at all. I don't know if this is a bug, but I tried it both in the stable release just using the function itself, and in the Beta .86 release.

Maybe you should post it in the bug reports, and have one of the Devs look at it.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

maybe this

#include <GUIConstants.au3>
#include <Misc.au3>

Opt("GUICoordMode", 1)
Opt("WinTitleMatchMode", 1)
WinActivate("Program Name")
WinWaitActive("Program Name")
While 1
    
    If _IsPressed(01) Then
        If WinActive("?Name?") Or WinActive("?Name?") Or WinActive("?Name?") Then
            $currentvalue = IniRead ("counter.ini", "counter", "currentcount", "0" ) + 1
            Iniwrite ( "counter.ini", "counter", "currentcount", $currentvalue )
        EndIf
    EndIf
    
WEnd

8)

NEWHeader1.png

Link to comment
Share on other sites

sorry its 3 am

#include <GUIConstants.au3>
#include <Misc.au3>

Opt("GUICoordMode", 1)
Opt("WinTitleMatchMode", 1)
WinActivate("Program Name")
WinWaitActive("Program Name")
While 1
    
    If _IsPressed(01) Then
    ;MsgBox(0,"test", " cool"); for testing
        If ControlGetFocus("210") >= "" Or  ControlGetFocus("112") >= "" Or  ControlGetFocus("211") >= "" Then
            $currentvalue = IniRead ("counter.ini", "counter", "currentcount", "0" ) + 1
            Iniwrite ( "counter.ini", "counter", "currentcount", $currentvalue )
        EndIf
    EndIf
    
WEnd

8)

EDIT

replaced 0 with ""

EDIT 2

removed extra Endif... Dah

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

  • Moderators

I'll attest that it worked also... What buttons are your talking.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I would be talking about 210, 112, and 211 which come to find out are the control ids for the buttons which is not what ControlGetFocus returns

I realized that ControlGetFocus("Program Name") will return the ClassNameNN.

210 is the Control ID for ImageButton3

112 is the Control ID for ImageButton2

211 is the Control ID for ImageButton6

Although its writing data, which is good it is still not doing it based on clicks to those three buttons

Any ideas?

By the way Ron if you get a chance will you look at my reply for my previous post

http://www.autoitscript.com/forum/index.php?showtopic=18186

Link to comment
Share on other sites

I would be talking about 210, 112, and 211 which come to find out are the control ids for the buttons which is not what ControlGetFocus returns

I realized that ControlGetFocus("Program Name") will return the ClassNameNN.

210 is the Control ID for ImageButton3

112 is the Control ID for ImageButton2

211 is the Control ID for ImageButton6

Although its writing data, which is good it is still not doing it based on clicks to those three buttons

Any ideas?

By the way Ron if you get a chance will you look at my reply for my previous post

http://www.autoitscript.com/forum/index.php?showtopic=18186

Actually... I hate guessing

what program

is it the internet

why dont you show your script

Dah

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

Sorry just didn't think it was important. I am trying to make a counter for my amount wagered at a online casino

Here is the code I have been messing with, it currently does not write to .ini

#include <GUIConstants.au3>
#include <Misc.au3>

Opt("GUICoordMode", 1)
Opt("WinTitleMatchMode", 1)
WinActivate("Casino")
WinWaitActive("Casino")
While 1
    
    If _IsPressed(01) Then
   ;MsgBox(0,"test", " cool"); for testing
        If ControlGetFocus("Casino") >= "ImageButton2" Or  ControlGetFocus("Casino") >= "ImageButton3" Or  ControlGetFocus("Casino") >= "ImageButton6" Then
            $currentvalue = IniRead ("counter.ini", "counter", "currentcount", "0" ) + 1
            Iniwrite ( "counter.ini", "counter", "currentcount", $currentvalue )
        EndIf
    EndIf
    
WEnd

Hope this helps

Link to comment
Share on other sites

ok this will do the trick.. all you need to do is put in the mouse area that covers the button(s)

example

top

left right

bottom

where $pos[0] > - 1 And $pos[0] < 12 is left and right of the button

and

$pos[1] > - 1 And $pos[1] < 12 is top and bottom of the button

#include <GUIConstants.au3>
#include <Misc.au3>

Dim $post = 0

Opt("GUICoordMode", 1)
Opt("WinTitleMatchMode", 1)
WinActivate("Casino")
WinWaitActive("Casino")
While 1
    
    If _IsPressed(01) Then
    ;MsgBox(0,"test", " cool"); for testing
        $pos = MouseGetPos()
        
    ; position of 1 button
        If $pos[0] > - 1 And $pos[0] < 12 And $pos[1] > - 1 And $pos[1] < 12 Then $post = 1
        
    ; position of 2 button
        If $pos[0] > - 1 And $pos[0] < 12 And $pos[1] > - 1 And $pos[1] < 12 Then $post = 1
        
    ; position of 3 button
        If $pos[0] > - 1 And $pos[0] < 12 And $pos[1] > - 1 And $pos[1] < 12 Then $post = 1

        If $post = 1 Then
            $currentvalue = IniRead ("counter.ini", "counter", "currentcount", "0" ) + 1
            Iniwrite ( "counter.ini", "counter", "currentcount", $currentvalue )
            $post = 0
        EndIf
            
    EndIf

WEnd

8)

NEWHeader1.png

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...