Jump to content

MouseClick skipping "y" coordinate


Recommended Posts

I have a script that I am trying to have a simple function to mouse click at a coordinate within the input box. My trouble is that I only want 1 input for X and Y rather than two separate. How can I make that work however when I use the function?

Example:

;The input box
$Input1 = GUICtrlCreateInput("X", #, #, #, #)

;Retrieving the coordinate
$Pos1 = MouseGetPos()
GUICtrlSetData($Input1, $Pos1[0] & ", " & $Pos1[1])

;How do I skip the "Y" definition? retrieving the X and Y from one string?
MouseClick("Left", $Input1)

;What I am essentially looking for:
MouseClick("Left", $Input1[0], $Input1[1])

 

 

Link to comment
Share on other sites

You should just get the y coordinate when you get the x coordinate and add it to the mouseclick or controlclick. What reason do you have to use just one variable for both the x and y coordinate? Do you mean x=1 and y=1 as in they are always the same value or do you want a 2d array to have the coordinates of x and y?

Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

 

I have a script that I am trying to have a simple function to mouse click at a coordinate within the input box. My trouble is that I only want 1 input for X and Y rather than two separate. How can I make that work however when I use the function?

Example:

;The input box
$Input1 = GUICtrlCreateInput("X", #, #, #, #)

;Retrieving the coordinate
$Pos1 = MouseGetPos()
GUICtrlSetData($Input1, $Pos1[0] & ", " & $Pos1[1])

;How do I skip the "Y" definition? retrieving the X and Y from one string?
MouseClick("Left", $Input1)

;What I am essentially looking for:
MouseClick("Left", $Input1[0], $Input1[1])

 

 

myClickFromXYstring_orSomeOtherName(  GUICtrlRead($Input1)  )
Func myClickFromXYstring_orSomeOtherName($sXYstring)
    Local $arrayFromStringXY = StringSplit( $sXYstring , ',' ) ; if you use a comma as separator
    If UBound( $arrayFromStringXY ) <> 3 Then Return ; because it failed to have 2 values
    MouseClick("Left", Int($arrayFromStringXY[1]) , Int($arrayFromStringXY[2]) )
EndFunc

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

I'm with computergroove, what exactly are you trying to do?  Here's what I understand so far:

1 - you want to click somewhere in your gui and record the x,y coords in your input box (why?)

2 - you then want to generate a mouseclick at the coordinates just recorded (again, why?   you already have the coords)

3 - you want to skip the y coord (I'm going to assume that you mean skip recording the y coord in a separate input control) (this one looses me...)

Maybe some detailed explanation will get you better help.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Well the reason for the input box is so you can either record a coordinate or input your own. As for the more detailed explanation, you can see that with the code

$Pos1 = MouseGetPos()
GUICtrlSetData($Input1, $Pos1[0] & ", " & $Pos1[1])

it is recording the coordinate value in a single input box displayed as

342, 294

This is just an example of what it might look like. What I am trying to do is then click while in a loop but the problem I am running into is that with the mouse click function it requires an X and Y coordinate, but my input text IS the X and Y coordinate, how can I tell my code to grab the first three numbers as the X and the last three as the Y without using two input boxes ($inputX, $inputY)

So the code would essentially be saying:

MouseClick("left", 342, 294)
;but by using only one variable (the $input1)
MouseClick("left", $input1 <--X coordinate, $input1 <-- Y coordinate)

Make better sense?

EDIT

The stringsplit function seems to be what I might be looking for, I tried incorporating into my code with no luck however.

Func Start()
GUICtrlSetData($Start, "Stop")
$Coord1 = StringSplit($Input1, ', ')
If UBound( $Coord1 ) <> 3 Then Return
   While 1
MouseClick("left", Int($Coord1[1]) , Int($Coord1[2]))
Sleep(500)
  WEnd
EndFunc
Edited by kjpolker
Link to comment
Share on other sites

Here is sample of the problem I am having, It is not clicking nor is it breaking the loop when $Start is pressed. I would imagine my Timer is messed up and my String Split.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

#Region ### START Koda GUI section ### Form=
Local $Pos1
$Coord = GUICreate("Coordinate", 194, 141)
$Button1 = GUICtrlCreateButton("Get Pos 1", 16, 8, 73, 25)
$Input1 = GUICtrlCreateInput("X", 104, 8, 60, 21)
$Start = GUICtrlCreateButton("Start", 60, 110, 73, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


WinSetOnTop("[CLASS:AutoIt v3 GUI]", "", 1)


Global $Coord1
HotKeySet( "{PAUSE}", "TogglePause")
HotKeySet( "{ESC}", "Terminate")


While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
Button1()
Case $Start
Start()
EndSwitch
 WEnd


Func Button1()
 If GUICtrlRead($Start) = "Stop" Then Return
   Local $dll = DllOpen("user32.dll")
While Not _IsPressed("01", $dll)
   Sleep(10)
WEnd
DllClose($dll)
   Local $Pos1 = MouseGetPos()
GUICtrlSetData($Input1, $Pos1[0] & ", " & $Pos1[1])
EndFunc

Func Start()
GUICtrlSetData($Start, "Stop")
$Coord1 = StringSplit($Input1, ', ')
If UBound( $Coord1 ) <> 3 Then Return
   While
 Tooltip("Running",0,0)
MouseClick("Right", Int($Coord1[1]) , Int($Coord1[2]))
Sleep(500)
Local $begin = TimerInit()
While TimerDiff($begin) > 0
Switch GUIGetMsg()
Case $gui_event_close
Exit
Case $Start
GUICtrlSetData($Start, "Start")
ExitLoop 2
EndSwitch
WEnd
   WEnd
EndFunc


Func TogglePause()
    Local $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Paused',0,0)
    WEnd
    ToolTip("")
 EndFunc


Func Terminate()
   Exit 0
EndFunc

There are obviously issues with what I have, I just don't know enough to correct the issues.

Edited by kjpolker
Link to comment
Share on other sites

do step 1 (reading values and click) - evaluate, see if it works. if you manage that, add next step (some loop which you can test out and you see it works how you want). dont make a whole  functions and and whatc how nothing goes. do step by step and you will get there

Link to comment
Share on other sites

 

Here is sample of the problem I am having, It is not clicking nor is it breaking the loop when $Start is pressed. I would imagine my Timer is messed up and my String Split.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

#Region ### START Koda GUI section ### Form=
Local $Pos1
$Coord = GUICreate("Coordinate", 194, 141)
$Button1 = GUICtrlCreateButton("Get Pos 1", 16, 8, 73, 25)
$Input1 = GUICtrlCreateInput("X", 104, 8, 60, 21)
$Start = GUICtrlCreateButton("Start", 60, 110, 73, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


WinSetOnTop("[CLASS:AutoIt v3 GUI]", "", 1)


Global $Coord1
HotKeySet( "{PAUSE}", "TogglePause")
HotKeySet( "{ESC}", "Terminate")


While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
Button1()
Case $Start
Start()
EndSwitch
 WEnd


Func Button1()
 If GUICtrlRead($Start) = "Stop" Then Return
   Local $dll = DllOpen("user32.dll")
While Not _IsPressed("01", $dll)
   Sleep(10)
WEnd
DllClose($dll)
   Local $Pos1 = MouseGetPos()
GUICtrlSetData($Input1, $Pos1[0] & ", " & $Pos1[1])
EndFunc

Func Start()
GUICtrlSetData($Start, "Stop")
$Coord1 = StringSplit($Input1, ', ')
If UBound( $Coord1 ) <> 3 Then Return
   While
 Tooltip("Running",0,0)
MouseClick("Right", Int($Coord1[1]) , Int($Coord1[2]))
Sleep(500)
Local $begin = TimerInit()
While TimerDiff($begin) > 0
Switch GUIGetMsg()
Case $gui_event_close
Exit
Case $Start
GUICtrlSetData($Start, "Start")
ExitLoop 2
EndSwitch
WEnd
   WEnd
EndFunc


Func TogglePause()
    Local $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Paused',0,0)
    WEnd
    ToolTip("")
 EndFunc


Func Terminate()
   Exit 0
EndFunc

There are obviously issues with what I have, I just don't know enough to correct the issues.

 

I have no idea what you upto but, here it is:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

#Region ### START Koda GUI section ### Form=
Local $Pos1
Global $Coord = GUICreate("Coordinate", 194, 141)
Global $Button1 = GUICtrlCreateButton("Get Pos 1", 16, 8, 73, 25)
Global $Input1 = GUICtrlCreateInput("X", 104, 8, 60, 21)
Global $Start = GUICtrlCreateButton("Start", 60, 110, 73, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


WinSetOnTop("[CLASS:AutoIt v3 GUI]", "", 1)


Global $Coord1
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            GUIDelete($Coord)
            Exit
        Case $Button1
            Button1()
        Case $Start
            Start()
    EndSwitch
WEnd


Func Button1()
    If GUICtrlRead($Start) = "Stop" Then Return
    GUICtrlSetData($Button1, "click")
    Local $dll = DllOpen("user32.dll")
    While Not _IsPressed("01", $dll)
        Sleep(10)
    WEnd
    DllClose($dll)
    Local $Pos1 = MouseGetPos()
    GUICtrlSetData($Button1, "got it")
    GUICtrlSetData($Input1, $Pos1[0] & ", " & $Pos1[1])
EndFunc   ;==>Button1

Func Start()
    GUICtrlSetData($Start, "Stop")
    Local $Coord1 = StringSplit(StringStripWS(GUICtrlRead($Input1), 8), ',')
    If UBound($Coord1) <> 3 Then
        GUICtrlSetData($Start, "Start")
        Return
    EndIf

;~  While 1
;~      ToolTip("Running", 0, 0)
    MouseClick("Right", Int($Coord1[1]), Int($Coord1[2]))
    GUICtrlSetData($Start, "Start")
;~      Sleep(500)
;~      Local $begin = TimerInit()
;~      While 1 ; TimerDiff($begin) > 0
;~          Switch GUIGetMsg()
;~              Case $gui_event_close
;~                  Exit
;~              Case $Start
;~                  GUICtrlSetData($Start, "Start")
;~                  ExitLoop 2
;~          EndSwitch
;~      WEnd
;~  WEnd
EndFunc   ;==>Start


Func TogglePause()
    Local $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Paused', 0, 0)
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause


Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.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...