Jump to content

Drawing a line to mouse position


Recommended Posts

Hello there,

I am new to the forum and this is my first post but please notify me if I did anything wrong o:).

I´d like to make a script that draws a line from any coordinate (in my example 0/0)  to the mouse position but I fail at deleting the old lines which results in a full covered screen :(.

I put a Sleep(500) in the loop but an If (IsArray($pos)) is going to replace it later.  I´d be happy to know how to delete the old lines or how to "refresh" the whole screen so there is only one line at a time visible.

 

Thanks in advice,

MilselimX

DrawLineToMousePos.au3

Link to comment
Share on other sites

Please try this

#Include <WinAPI.au3>
#Include <WindowsConstants.au3>

HotKeySet ("{ESC}", "Final")
HotKeySet ("{SPACE}", "Start")

Global $Wnd, $pos

while 1
    Sleep(10)
WEnd


Func Start()
    $pos = MouseGetPos()
    DrawLine(0, 0, $pos[0], $pos[1], 1, 0xFF)
EndFunc


Func DrawLine($x1, $y1, $x2, $y2, $width, $colour)
    Local $DC, $Pen, $obj_orig
    $Wnd = WinGetHandle("[ACTIVE]", "")
  _WinAPI_RedrawWindow($Wnd, 0, 0, $RDW_INVALIDATE+$RDW_ALLCHILDREN + $RDW_UPDATENOW )

    $DC = _WinAPI_GetWindowDC($Wnd)
    $Pen = _WinAPI_CreatePen($PS_SOLID, 2, 0xFF)
    $obj_orig = _WinAPI_SelectObject($DC, $Pen)

    _WinAPI_MoveTo($DC,$x1,$y1)
    _WinAPI_LineTo($DC,$pos[0],$pos[1])
     ;Return $DC
    ;Sleep(500)
    _WinAPI_ReleaseDC($Wnd,$DC)
EndFunc

Func Final()
   _WinAPI_RedrawWindow($Wnd, 0, 0, $RDW_INVALIDATE+$RDW_ALLCHILDREN + $RDW_UPDATENOW )
    Exit
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...