Jump to content

Examples for interactive coordinate selector or point picker?


TheDcoder
 Share

Recommended Posts

Hello, it has been a long time since I have posted here :D

I am working on an AutoIt project where I need to enable to user to interactively choose any point or coordinate on the screen... something like a big overlay where the user can click anywhere on the screen to select that point. @UEZ's screenshot tool may have something similar to what I need:

I just checked the source code for the tool and I see that the Mark_Area function has a part in selecting the area to screenshot, I tried to figure out how it works but it is simply too complex and long...

So I was wondering if there were any examples of interactively selecting points on a screen? Maybe an UDF that I can just use in my script to make the whole thing a matter of adding few lines :lmao:o:)

Thank you for the replies in advance!

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Thank you very much @UEZ :thumbsup:

I fiddled with your _GDIPlus example (which strangely doesn't seem to be using GDI+ much...) and in the end I created this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

; #FUNCTION# ====================================================================================================================
; Name ..........: InteractiveCoordinateSelect
; Description ...: Lets the user interactively select a point on the screen
; Syntax ........: InteractiveCoordinateSelect()
; Parameters ....: None
; Return values .: Success: An array with the X and Y positions of the selected point
;                  Failure: False (This happens when the overlay window is closed)
; Author ........: Damon Harris (TheDcoder)
; Remarks .......: Inspired by UEZ's _GDIPlus_MarkScreenRegionAnimated
; Link ..........: https://git.io/fh9md
; Example .......: See Example.au3
; ===============================================================================================================================
Func InteractiveCoordinateSelect()
    Local $iOriginalGUIMode = Opt("GUIOnEventMode")
    Opt("GUIOnEventMode", 0)

    Local Const $hFullScreen = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]")
    Local Const $aFullScreen = WinGetPos($hFullScreen)

    Local $hOverlay = GUICreate("", $aFullScreen[2], $aFullScreen[3], $aFullScreen[0], $aFullScreen[1], BitOR($WS_CLIPCHILDREN, $WS_POPUP), $WS_EX_TOPMOST)
    GUISetCursor(3 , $GUI_CURSOR_OVERRIDE, $hOverlay)
    WinSetTrans($hOverlay, "", 1)

    GUISetState(@SW_SHOW)

    Local $aCursorInfo
    While True
        If GUIGetMsg() = $GUI_EVENT_CLOSE Then
            $aCursorInfo = False
            ExitLoop
        EndIf
        $aCursorInfo = GUIGetCursorInfo($hOverlay)
        If $aCursorInfo[2] Then
            ReDim $aCursorInfo[2]
            ExitLoop
        EndIf
    WEnd

    GUIDelete($hOverlay)
    Opt("GUIOnEventMode", $iOriginalGUIMode)
    Return $aCursorInfo
EndFunc

A very simplified and barebones version of the UDF... I did however notice that I am not getting my full resolution (1920x1080) when I select the bottom and right most point on my screen, can someone else confirm that this is happening for them as well?

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

For those who want a script that they can paste together to just run the test, here you go:

Example()

Func Example()
    Local $aPosition = InteractiveCoordinateSelect()
    ConsoleWrite("X: " & $aPosition[0] & @CRLF & "Y: " & $aPosition[1] & @CRLF) 
EndFunc

; Don't forget to include the function code in your script... if that was not already obvious.

I appricate you testing.

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

  • 3 years later...

Hey, made an account just to thank you.

 

Used your code so i could select a point in the screen to run a script in a loop for that point, everytime i started the scrip.

 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $Paused, $Runner
HotKeySet("{F2}", "Terminate")

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

#your code start
Func InteractiveCoordinateSelect()
    Local $iOriginalGUIMode = Opt("GUIOnEventMode")
    Opt("GUIOnEventMode", 0)

    Local Const $hFullScreen = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]")
    Local Const $aFullScreen = WinGetPos($hFullScreen)

    Local $hOverlay = GUICreate("", $aFullScreen[2], $aFullScreen[3], $aFullScreen[0], $aFullScreen[1], BitOR($WS_CLIPCHILDREN, $WS_POPUP), $WS_EX_TOPMOST)
    GUISetCursor(3 , $GUI_CURSOR_OVERRIDE, $hOverlay)
    WinSetTrans($hOverlay, "", 1)

    GUISetState(@SW_SHOW)

    Local $aCursorInfo
    While True
        If GUIGetMsg() = $GUI_EVENT_CLOSE Then
            $aCursorInfo = False
            ExitLoop
        EndIf
        $aCursorInfo = GUIGetCursorInfo($hOverlay)
        If $aCursorInfo[2] Then
            ReDim $aCursorInfo[2]
            ExitLoop
        EndIf
    WEnd

    GUIDelete($hOverlay)
    Opt("GUIOnEventMode", $iOriginalGUIMode)
    Return $aCursorInfo
 EndFunc
 
#your code end

Buy()

Func Buy()
   local $aPosition = InteractiveCoordinateSelect()
   $x1 =  $aPosition[0] & @CRLF
   $y1 =  $aPosition[1] & @CRLF
   $Runner = Not $Runner
    While $Runner
         MouseClick("left", $x1, $y1, 3, 0)
        sleep (100)
        MouseClick("left", 698, 497, 5, 0)
        sleep(400)
         MouseClick("left", 505, 358, 5, 0)
        sleep(200)
        Send("{BACKSPACE}")
        sleep(50)
        Send("99")
        sleep(200)
        MouseClick("left", 488, 455, 5, 0)
        sleep(500)
        Mouseclick("left", 493, 375, 5, 0)
        sleep(50)
   WEnd
EndFunc

 

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

×
×
  • Create New...