Sign in to follow this  
Followers 0
Sander

Problem with making my script do stuff in the right order.

5 posts in this topic

I'm making a tiny script that will help getting the hex code of a color, im just doing it to learn and its my first program so i guess there will be alot of sloppy code :)

So im trying to get it to show the hex in another window, Form2, when i press the key to get the hex, Form1 will close, and form 2 will open with the hex in input1. However when i try to make it so that when i press "Copy to clipboard" it exits form2 and re-enters form1 it just goes straight trough it without me needing to press anything, which means it goes right trough form2 without letting me do anything. The way i have it now both is there when i press the key and its kinda annoying :party:

#include-once
#include <GUIConstants.au3>
$version = "v1.1"
$title = "PixelGet "
$strek = " - "
$helps = "Instructions"
$Form1 = GUICreate($title & $version, 179, 157, 285, 227)
GUISetFont(8, 800, 0, "MS Sans Serif")
GUISetBkColor(0x000000)
$Label1 = GUICtrlCreateLabel("PixelGet v1.0", 40, 0, 109, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
$Label3 = GUICtrlCreateLabel("Use:", 72, 24, 30, 17)
GUICtrlSetColor(-1, 0x0000FF)
$Label4 = GUICtrlCreateLabel("Hold you're mouse over", 24, 40, 137, 17)
GUICtrlSetColor(-1, 0x00FF00)
$Label5 = GUICtrlCreateLabel("what you want the hex code of", 16, 56, 155, 17)
GUICtrlSetColor(-1, 0x00FF00)
$Label6 = GUICtrlCreateLabel("and press F10 to get it.", 24, 72, 136, 17)
GUICtrlSetColor(-1, 0x00FF00)
$Label7 = GUICtrlCreateLabel("Hold down F9 for information", 8, 88, 167, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
$Label8 = GUICtrlCreateLabel("Press ESC to exit the program!", 0, 104, 177, 17)
GUICtrlSetColor(-1, 0xFF00FF)
$Label9 = GUICtrlCreateLabel("MMOwned", 88, 128, 75, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x008000)
$Label2 = GUICtrlCreateLabel("Zordin @", 8, 128, 78, 17)
GUICtrlSetColor(-1, 0xFFFF00)
GUISetState(@SW_SHOW)

HotKeySet("{F10}", "grab")
HotKeySet("{ESC}", "foo")
HotKeySet("{F9}", "help")

While 1
    Sleep(100)
WEnd

Func grab()
    $pos = MouseGetPos()
    $pixel_hex = '0x' & Hex(PixelGetColor($pos[0], $pos[1]), 6)
    $pixel_dec = Dec($pixel_hex)
    WinSetState($form1, '', @SW_HIDE)
    $Form2 = GUICreate("Hex Code:", 237, 82, 193, 125)
    $copy = GUICtrlCreateButton("Copy to Clipboard", 0, 40, 235, 41, 0)
    $Input1 = GUICtrlCreateInput($pixel_hex, 0, 0, 233, 45)
    GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFF0000)
    WinSetState($form2, '', @SW_SHOW)
        if $copy Then
            ClipPut(GuiCtrlread($input1))
            WinSetState($form1, '', @SW_SHOW)
        EndIf
    Sleep(2000)
    ToolTip("")
EndFunc  ;==>grab

Func foo()
    Exit
EndFunc  ;==>foo

func help()
    if $helps then
        msgbox(48, "PixelGet v1.0 - Info", "This will help you get the hex codes of colors, its easy to use all you have to do it take the pointer over the color you want the hex code of and press F10.                                                                             This was made by Zirdon at MMOwned")
    endif
EndFunc

Any1 here that can help out a newb? :idea:

Share this post


Link to post
Share on other sites



Func grab()

$pos = MouseGetPos()

$pixel_hex = '0x' & Hex(PixelGetColor($pos[0], $pos[1]), 6)

$pixel_dec = Dec($pixel_hex)

WinSetState($form1, '', @SW_HIDE)

$Form2 = GUICreate("Hex Code:", 237, 82, 193, 125)

$copy = GUICtrlCreateButton("Copy to Clipboard", 0, 40, 235, 41, 0)

$Input1 = GUICtrlCreateInput($pixel_hex, 0, 0, 233, 45)

GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")

GUICtrlSetColor(-1, 0xFF0000)

WinSetState($form2, '', @SW_SHOW)

if $copy Then

ClipPut(GuiCtrlread($input1))

WinSetState($form1, '', @SW_SHOW) ;here is your mistake

EndIf

Sleep(2000)

ToolTip("")

EndFunc ;==>grab

Corrected function:

Func grab()
    $pos = MouseGetPos()
    $pixel_hex = '0x' & Hex(PixelGetColor($pos[0], $pos[1]), 6)
    $pixel_dec = Dec($pixel_hex)
    WinSetState($form1, '', @SW_HIDE)
    $Form2 = GUICreate("Hex Code:", 237, 82, 193, 125)
    $copy = GUICtrlCreateButton("Copy to Clipboard", 0, 40, 235, 41, 0)
    $Input1 = GUICtrlCreateInput($pixel_hex, 0, 0, 233, 45)
    GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFF0000)
    WinSetState($form1, '', @SW_HIDE)
    WinSetState($form2, '', @SW_SHOW)
        if $copy Then
            ClipPut(GuiCtrlread($input1))
        EndIf
    Sleep(2000)
    ToolTip("")
EndFunc ;==>grab

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Ok, some improvement :) Now the form1 doesnt show up after i get the color, but i want it so that when u press "Copy to Clipboard" it copies it, then exits form2 and enters form1

Edited by Sander

Share this post


Link to post
Share on other sites

First off, is it Zordin or Zirdon?

You're not reading GUI messages or responding to GUI events, so that's why it's not doing what you expect.

$copy is the handle to the button you created, so it's going to be non-zero.

That means this line is always true, not just when you click the button:

if $copy Then

Try this instead:
Func grab()
    $pos = MouseGetPos()
    $pixel_hex = '0x' & Hex(PixelGetColor($pos[0], $pos[1]), 6)
    $pixel_dec = Dec($pixel_hex)
    WinSetState($Form1, '', @SW_HIDE)
    $Form2 = GUICreate("Hex Code:", 237, 82, 193, 125)
    $copy = GUICtrlCreateButton("Copy to Clipboard", 0, 40, 235, 41, 0)
    $Input1 = GUICtrlCreateInput($pixel_hex, 0, 0, 233, 45)
    GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFF0000)
    GUISetState(@SW_SHOW, $Form2)
    GUISwitch($Form2) ; Activate Second Form
    Do
    Until GUIGetMsg() = $copy ; Wait until button is pressed
    ClipPut(GUICtrlRead($Input1))
    WinSetState($Form1, '', @SW_SHOW)
    GUIDelete($Form2)
    GUISwitch($Form1)
    ToolTip("")
EndFunc   ;==>grab

Other suggestions: It's better to create the windows ahead of time and show/hide them as needed, so you don't leave any orphan windows behind.


[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks, that worked! Guess ill experiment with gui events :) It's Zordin, had a typo there xD

Other suggestions: It's better to create the windows ahead of time and show/hide them as needed, so you don't leave any orphan windows behind.

How do i do that? ^^

Edited by Sander

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