freyaharts

get coordinates and color of mouse

23 posts in this topic

#1 ·  Posted (edited)

getting coords is working fine but getting the color gives me error

HotKeySet ("{esc}", "_Exit")

#include <Misc.au3>

$Coords = AskUser()
call ("Start")


Func AskUser()
    MsgBox(0, "User Input", "Please click mouse your screen" & @CRLF & "Press OK, and then move your mouse there and click")
    Do
        Sleep(50)
    Until _IsPressed(01)
    $Coords = MouseGetPos()
Local $Color = PixelGetColor($coords[0], $coords[1])
    
    MsgBox(0, "info", "Your coords and color have been stored for later use")
    Return $Coords
EndFunc 




Func Start()
While 1

if pixelgetcolor($coords[0],$coords[1]) = $Color  then
   sleep (200)
   ;run whole script

Else
   sleep (100)
   endif

wend
EndFunc



Func _Exit()
Exit
EndFunc

 

 

Edited by freyaharts

Share this post


Link to post
Share on other sites



#3 ·  Posted

when i run it .. it doesnt seem set the value and my whole script loop didnt work

Share this post


Link to post
Share on other sites

#4 ·  Posted

Which value? It really would help to be much more specific.
You have an msgbox() in there ...  what is shown?
When I run it it works fine after fixing the syntax error in this line:

if pixelgetcolor ($Coords[0,  $Coords[1]) = 0x012549 then

It is missing a ] after the 0.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#5 ·  Posted

sorry my objective is unclear .. heres what im trying to do

a message box will pop out and ask the user to click the mouse and set the pixelgetcolor and then run the loop

 

HotKeySet ("{home}", "SetBlueCoords")
HotKeySet ("{END}", "_Exit")

While 1
Sleep(200)
WEnd




func SetBlueCoords()

   MsgBox(0, "User Input", "Please click the screen on blue pixel bar" & @CRLF & "Press OK, and then move your mouse there and click")
    Do
      Sleep(50)
    Until _IsPressed(01)
    $Blue= MouseGetPos()

   $blueHex = & Hex($blueHex, 6))

call ("start")
EndFunc  



func start()

while 1

if pixelgetcolor ($blue[0], $[blue[1]) <> $blueHex  then

;run the whole script

endif

wend

endfunc



Func _Exit()
Exit
EndFunc

 

Share this post


Link to post
Share on other sites

#6 ·  Posted

Understood...  but it is still unclear what the issue is with the script. So what is your question or what isn't working?
Also define what program/process you are trying to automate so we understand.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#7 ·  Posted

its for data entry job ... the user will click the position of progress bar on how many percent they wish before doing another task for copying anoter file.. 

w7hKsdy.png

 

when i run it i got this error message

 

$blueHex = & Hex($blueHex, 6))

$blueHex = & Hex($^ ERROR

Error: varriable used without being declared.

 

im kinda new to this automation.. i hope you help me 

 

Share this post


Link to post
Share on other sites

#8 ·  Posted

You get that error because you have nowhere define that variable $BlueHex. 
So simply add it with its appropriate value at the top of the script.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#9 ·  Posted

thank you so much, im kinda new to this. can you make an example how to achieve that?

Share this post


Link to post
Share on other sites

#10 ·  Posted

1 minute ago, freyaharts said:

can you make an example how to achieve that?

No ...  read again what I type and try to understand and play with that. 
You creted the posted script su I can only assume you created it and as such should understand it. ;)

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#11 ·  Posted

hi im kinda new to this i want to get color and coordinates stored the data and use it for whole loop script

coordinates works pecfectly however color doesnt seem work 

 

any ideas?

 

 

HotKeySet ("{esc}", "_Exit")

#include <Misc.au3>

$Coords = AskUser()
call ("Start")


Func AskUser()
    MsgBox(0, "User Input", "Please click mouse your screen" & @CRLF & "Press OK, and then move your mouse there and click")
    Do
        Sleep(50)
    Until _IsPressed(01)
    $Coords = MouseGetPos()
Local $Color = PixelGetColor($coords[0], $coords[1])
    
    MsgBox(0, "info", "Your coords and color have been stored for later use")
    Return $Coords
EndFunc 




Func Start()
While 1

if pixelgetcolor($coords[0],$coords[1]) = $Color  then
   sleep (200)
   ;run whole script

Else
   sleep (100)
   endif

wend
EndFunc



Func _Exit()
Exit
EndFunc

 

Share this post


Link to post
Share on other sites

#12 ·  Posted

6 minutes ago, Jos said:

No ...  read again what I type and try to understand and play with that. 
You creted the posted script su I can only assume you created it and as such should understand it. ;)

Jos

its been actually a week still trying to figure it out  on my own.... i tried to slam my head on desk but still didnt get the idea .. im so hopeless :( 

Share this post


Link to post
Share on other sites

#13 ·  Posted

freyaharts,

Stick to just the one thread please - merged.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#14 ·  Posted

So again, where in your script have you defined the variable $BlueHex ?  (Shouldn't be a real hard question..right?)

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#15 ·  Posted

1 hour ago, Jos said:

So again, where in your script have you defined the variable $BlueHex ?  (Shouldn't be a real hard question..right?)

Jos

i merge my topic and remove the $bluehex.. please take a look in the top 

Share this post


Link to post
Share on other sites

#16 ·  Posted

im getting variable didnt declared error

when  already declared the variable?

 

EmK4yFR.png

Share this post


Link to post
Share on other sites

#17 ·  Posted

       freyaharts,

That variable is declared as Local to the AskUser function and so is invisible to the Start function.

The Variables - using Global, Local, Static and ByRef tutorial in the Wiki might be a useful read to help you understand more about scoping variables.

M23

 

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#18 ·  Posted

ok i tried to remove the local ,global,  but still get variable used without being declared

Local $Color = PixelGetColor($coords[0], $coords[1])

Share this post


Link to post
Share on other sites

#19 ·  Posted

freyaharts,

Declare the variable as Global at the top of the script and then it can be seen by both functions - as long as you do not redeclare it as Local inside one of them.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#20 ·  Posted

i put global to the top before all the functions but now i get error.. it asks for $coords varrible?

 

Global $Color = PixelGetColor($coords[0], $coords[1])

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