Jump to content

Recommended Posts

Hello . I implemented script like this

But the vars $iX1 $iY1 are counting from the desktop start and I want it coords by window

This not work with this script Opt("MouseCoordMode", 0)

Func Mark_Rect()
    Local $aMouse_Pos, $hMask, $hMaster_Mask, $iTemp
    Local $UserDLL = DllOpen("user32.dll")

    ; Create transparent GUI with Cross cursor
    $hCross_GUI = GUICreate("Test", @DesktopWidth, @DesktopHeight - 20, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)
    WinSetTrans($hCross_GUI, "", 8)
    GUISetState(@SW_SHOW, $hCross_GUI)
    GUISetCursor(3, 1, $hCross_GUI)

    Global $hRectangle_GUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)

    ; Wait until mouse button pressed
    While Not _IsPressed("01", $UserDLL)

    ; Get first mouse position
    $aMouse_Pos = MouseGetPos()
    global $iX1 = Round($aMouse_Pos[0], 2)
    global $iY1 = Round($aMouse_Pos[1], 2)

    ; Draw rectangle while mouse button pressed
    While _IsPressed("01", $UserDLL)

        $aMouse_Pos = MouseGetPos()

        $hMaster_Mask = _WinAPI_CreateRectRgn(0, 0, 0, 0)
        $hMask = _WinAPI_CreateRectRgn($iX1,  $aMouse_Pos[1], $aMouse_Pos[0],  $aMouse_Pos[1] + 1) ; Bottom of rectangle
        _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
        $hMask = _WinAPI_CreateRectRgn($iX1, $iY1, $iX1 + 1, $aMouse_Pos[1]) ; Left of rectangle
        _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
        $hMask = _WinAPI_CreateRectRgn($iX1 + 1, $iY1 + 1, $aMouse_Pos[0], $iY1) ; Top of rectangle
        _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
        $hMask = _WinAPI_CreateRectRgn($aMouse_Pos[0], $iY1, $aMouse_Pos[0] + 1,  $aMouse_Pos[1]) ; Right of rectangle
        _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2)
        ; Set overall region
        _WinAPI_SetWindowRgn($hRectangle_GUI, $hMaster_Mask)

        If WinGetState($hRectangle_GUI) < 15 Then GUISetState()

        ; Get second mouse position
    global $iX2 = Round($aMouse_Pos[0], 2)
    global $iY2 = Round($aMouse_Pos[1], 2)

    ; Set in correct order if required
    If $iX2 < $iX1 Then
        $iTemp = $iX1
        $iX1 = $iX2
        $iX2 = $iTemp
    If $iY2 < $iY1 Then
        $iTemp = $iY1
        $iY1 = $iY2
        $iY2 = $iTemp

    If _IsPressed("01", $UserDLL) = 0 Then
        _GDIPlus_Startup ()
        $hDC = _WinAPI_GetWindowDC(0)
        $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC)
        ;Stworz pedzel i kolor, width
        ;$hPen = _GDIPlus_PenCreate(0x00FF00)
        ; Rysowanie linii

        ; middle of rectangle
        $xMiddle = ( $iX1 + $iX2 ) / 2
        $yMiddle = ( $iY1 + $iY2 ) / 2

        _GDIPlus_GraphicsDrawRect( $hGraphic, $xMiddle-20, $yMiddle-20, 40, 40)



EndFunc   ;==>Mark_Rect


Link to post
Share on other sites

Both work for me also long as the window is active:


#include <EditConstants.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <StringConstants.au3>
#include <WindowsConstants.au3>

Opt("MouseCoordMode", 0) ; Per Window
; Opt("MouseCoordMode", 2) ; Per Ctrl


Func Main()

    Local $hGUI = GUICreate("Test Window", 280, 75, @DesktopWidth - 300, 10, BitXOR($GUI_SS_DEFAULT_GUI, $WS_MINIMIZEBOX), $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
    Local $hOutput = GUICtrlCreateLabel("", 10, 10, 260, 65, $SS_SUNKEN + $SS_CENTER + $SS_CENTERIMAGE)
    GUICtrlSetFont($hOutput, 14, $FW_SEMIBOLD)
    GUISetState(@SW_SHOW, $hGUI)

    WinActivate("Test Window")

    Local $aMouse[2]
    While 1
        $hMsg = GUIGetMsg()
        $aMouse = MouseGetPos()
        GUICtrlSetData($hOutput, $aMouse[0] & ", " & $aMouse[1])
            Case $hMsg = $GUI_EVENT_CLOSE




Edited by rcmaehl

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

Cisco FinesseGithubIRC UDFWindowEx UDF


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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Tarakesh
      I have a situation where the desktop is designed in java swings. The nodes JTree is not allowing me to do checkbox selection using "spacebar". I am able to navigate through the nodes using up, down arrow and a tab. When I reach to the desire node selection, mouse left click is not working due a flaw a JTree core. However since it is selected, if mouse cursor auto moved to the position of the selection and send a "click"  then it should be solved. Any ideas much appreciated. 
      the problem with having fixed coordinates are the main windows is divided to 2panels where right panel containing this JTree can be expanded or shrink-ed.

    • By 1905russell
      Hello wise people of the forums – long time since I’ve asked for assistance – it’s me, the Autoit dabbling accountant who is not a programmer (my standard disclaimer).
      Is there somewhere in the forums that I can find a snippet that creates a moving dashstyle rectangle, similar to the one displayed when copying (“^C”) in excel? I’ve searched, but surprisingly could not find. Your help is greatly appreciated.
    • By DiveHigh
      Hello There!  
      I've encountered a small issue i just cant seem to program my way out of...

      What im doing is:        ;or rather, what im trying to do is
      Pixelsearch for a color, within a part of my screen,
      If color is present, i will rightclick it, for a menu to appear,
      in which i want to Leftclick an option. Simplicity itself.   

      The issue is that because this menu appears in different parts of my screen, its complicated to select the option i want to click.
      There is no special color to it, and i cannot define the area in which to click, because the menu appears different places.
      The only thing that is in common for the menu is that the Leftclick needs to be (lets say) 30pixels below the rightclick

      What can be done,  but seemingly not by me, is to get the coordinates of the rightclick, and use them as the "starting point" from where the coordinates for the leftclick will be.
      (Not sure if that makes sence, but maybe the code below will help you understand)

      You guys like example codes, so therefore i will give it my best shot, and hope it proves usefull

      $pos = Pixelsearch(200, 400, 200, 400, 0xFFFFFF)        ;This color is what i need to rightclick to bring up the menu
      If not @Error then                                                               ;If the color is present
      (Mouseclick("Right", $pos[0], $pos[1], 1, 1)                   ;Rightclick it, to bring up menu
      ;Here comes the part i cannot get to work
      $x = MousegetPos(X)                                                          ;To get the Coordinate "X", so we can calculated with it for the position of the leftclick
      $y = MousegetPos(Y)                                                           ; To get the Coordinate "Y", so that can be calculated with for the position of the leftclick

      MouseClick("Left", $x[0], $y-30[1], 1, 1)                         ;This was supposed to give me a leftclick that is 30pixels below the rightclick.
      (The MouseGetPos(X), may seem as a waste of space in this example, but in my script i will need both. 
              Im only using one in the example, mainly so that i wont confuse myself, but also to make it easier to digest for you guys)

      I have not been able to find any topic that covers this, but my apologies if such a topic already exist in the forums. 

      Maybe while im at it, can i ask,   what good does the [0] and [1] do, when using a "$variable" as coordinate?   

      Thanks in advance
      - DiveHigh
    • By NiceBoy1234
      I want to get the window coordinates of the command line window I tried following but it cannot acces the variable $aPos...
      Local $sCommandlinePath = "C:\Windows\system32\cmd.exe" RunCm() Func RunCm() RunWait($sCommandlinePath) ; Retrieve the position as well as height and width of the active window. Local $aPos = WinGetPos("[CLASS:ConsoleWindowClass]") ; Display the array values returned by WinGetPos. MsgBox($MB_SYSTEMMODAL, "", "X-Pos: " & $aPos[0] & @CRLF & _ "Y-Pos: " & $aPos[1] & @CRLF & _ "Width: " & $aPos[2] & @CRLF & _ "Height: " & $aPos[3]) EndFunc While 1 Sleep(1000) RunCm() WEnd 
    • By algiuxas
      I'm weak at mathematic, how to calculate blue point position? I only know red points positions, and arc degree:

      Can anybody write an example, function?
  • Create New...