Jump to content

Recommended Posts

Posted

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

Posted (edited)

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
Posted

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

Posted

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
Posted

Whoops, just checked the help file myself, you seem to be using the _IsPressed function correctly.

I wonder if GUIControlRead might work in this situation?

-DRX
  • Moderators
Posted

Did you try using the direct path to the ini?

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.

  • Moderators
Posted

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.

Posted

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

Posted (edited)

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

Posted

Yea!

It actually writes to the ini, but it writes if I click anywhere not just those three buttons, and it is not incrimenting in 1's it is some weird increment.

Any ideas?

  • Moderators
Posted

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.

Posted

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

Posted (edited)

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

Posted

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

Posted

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

Posted (edited)

even better if you use the mouse coodinates

Opt("MouseCoordMode", 2) ;1=absolute, 0=relative, 2=client

EDIT... need to put a sleep in the While Loop...like

Sleep(20)

8)

Edited by Valuater

NEWHeader1.png

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
  • Recently Browsing   0 members

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