Jump to content

Need help with GUICtrlCreateInput


Recommended Posts

Hey how can I make Autoit to write in its own GUICtrlCreateInput.

Here is example of my script

#include <GUIConstants.au3>

GUICreate("bot", 210, 200)

$called = GUICtrlCreateInput ($pizza, 140, 70, 50, 25)

$lab = GUICtrlCreateLabel("pizzas:", 50, 70, 80, 20)

GUISetState(@SW_SHOW)

while 1

$1col1=pixelgetcolor(10,10)

If $1col1=16777215 Then

$pizza=1

EndIf

WEnd

I want my program to look at pixel and when it finds right color, enter its value in an input box. However, I cant leave it like this, because value wasnt declared before hand. And if I do declare it in the begging then it starts going back and forth with two values. Any solutions to my problem?

(and what is the right way to post scripts)

keywen.com

Link to comment
Share on other sites

  • Moderators

nusaki,

You need to declare your variables first. Then use GUICtrlSetData to change the value in the input:

#include <GUIConstants.au3>

; Declare variables
$pizza = 0
$1col1 = 0

GUICreate("bot", 210, 200)
$called = GUICtrlCreateInput($pizza, 140, 70, 50, 25)
$lab = GUICtrlCreateLabel("pizzas:", 50, 70, 80, 20)
GUISetState(@SW_SHOW)

While 1

    ; just for demonstration purposes            <<<<<<<<  Delete
    If @SEC = 30 Then $1col1 = 16777215     ;<<<<<<<<  Delete
    ;$1col1 = PixelGetColor(10, 10)              <<<<<<<<  Uncomment
    If $1col1 = 16777215 Then
        $pizza += 1                         ; Increase pizza each time
        GUICtrlSetData($called, $pizza)
        $1col1 = 0                      ;<<<<<<<<  Delete; Reset the colour until next time
    EndIf

    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit ;<<<<<<<< Now your [X] button will exit!

WEnd

You will see that I have changed the code slightly so that it fires once every minute (at :30 to be precise). The lines marked with <<<<<<<<< will need to amended as shown to get your original code back.

Two more points:

1. If the pixel stays the trigger colour for a while, you will need to have another loop to wait until the pixel is no longer that colour - otherwise you will add to the $pizza variable continuously while the pixel is the trigger colour rather than each time it changes. It will look something like this:

If $1col1 = 16777215 Then
    $pizza += 1                         ; Increase pizza count
    GUICtrlSetData($called, $pizza)
    Do
        Sleep(10)                       ; Important or your CPU maxes out
    Until $1col1 <> 16777215            ; Loop until the pixel is no longer the trigger colour
EndIf

2. I added a way to exit using the red [X] - always a good idea. ;-)

Ask if anything is unclear.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thank you Melba.

Check pix every 30 seconds isnt ideal for me. What Im trying to create is a bot that keeps track of a pot for online poker game and that number is increasing every second or so. So as number increase in a poker game it should simultaneously increase in my bot. Also here is another problem Pot amount isn't always showing is here way to keep old number untill it start showing again.

I wanted to use GUICtrlCreateInput because its easy to copy and paste.

So my Idea was to use GetColor and identify number and once its identified write it in GUICtrlCreateInput and keep it there as long as it doesnt change.

May be you know a better way to insert number in GUICtrlCreateInput?? Or may be I should use a different approach?

Edited by nusaki

keywen.com

Link to comment
Share on other sites

  • Moderators

nusaki,

My apologies if I confused you - the 30sec timer was only to show you how the input value can be changed.

As I tried to explain earlier, you can reset the code so that it will only increase the $pizza number when the colour changes at pixel (10, 10):

#include <GUIConstantsEx.au3>

$pizza = 0
$1col1 = 0

GUICreate("bot", 210, 200)
$called = GUICtrlCreateInput($pizza, 140, 70, 50, 25)
$lab = GUICtrlCreateLabel("pizzas:", 50, 70, 80, 20)
GUISetState(@SW_SHOW)

While 1

    $1col1 = PixelGetColor(10, 10)
    If $1col1 = 16777215 Then
        $pizza += 1                        ; Increase pizza count
        GUICtrlSetData($called, $pizza)
        Do
            If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
        Until $1col1 <> 16777215           ; Loop until the pixel is no longer the trigger colour
    EndIf

    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit

WEnd

However, if you are trying to keep track of a number on screen, I do not believe this is best way to do it. There are numerous topics on reading from screens - try searching! :-)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...