Skip to content

Instantly share code, notes, and snippets.

@TheDcoder
Last active February 5, 2019 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheDcoder/c6120bfd0505e15871403a50e5809e9b to your computer and use it in GitHub Desktop.
Save TheDcoder/c6120bfd0505e15871403a50e5809e9b to your computer and use it in GitHub Desktop.
AutoIt UDF for interactively selecting a coordinate/point on the screen
#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 .......: No
; ===============================================================================================================================
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
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment