Jump to content

Line That Follows Cursor


Recommended Posts

Hey, All!

 

I was looking into the help file at all the drawing utilities and I was wondering if you draw a translucent line that follows your cursor. Upon looking for ideas I came across this thread (1.0) and saw UEZ's response. I also came across another post that UEZ replied to and found this reply (1.1) where he shows how you can draw on the desktop. This is what I'm looking for however I'd still like to be able to interact with a designated application and have the line/curve/vector passively follow it. Obviously we don't move our cursor very linearly so it would have to be able to draw on vectors. Am I over complicating this? 

Any ideas or starting points I should look more into? 

 

 

 

1.0

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

Global Const $aFullScreen = WinGetPos(WinGetHandle("[TITLE:Program Manager;CLASS:Progman]"))
Global $iHeight = 4
Global Const $hGUI = GUICreate("Screen Ruler Underline for free :-)", $aFullScreen[2], $iHeight, $aFullScreen[0], MouseGetPos(1), $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TRANSPARENT))
GUISetBkColor(0x000000)
WinSetTrans($hGUI, "", 0xA0)
GUISetState()

HotKeySet("{ESC}", "_Exit")

Do
    WinMove($hGUI, "", $aFullScreen[0], MouseGetPos(1))
Until Not Sleep(50)

Func _Exit()
    GUIDelete()
    Exit
EndFunc

_____________

1.1

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

AutoItSetOption("GUIOnEventMode", 1)

Global $hGUI, $hDC, $hPen, $obj_orig
$hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
WinSetTrans($hGUI, "", 1)
GUISetState()
_line()

Func _line()
    $hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop)
    $hPen = _WinAPI_CreatePen($PS_SOLID, 2, 0x00ff)
    $obj_orig = _WinAPI_SelectObject($hDC, $hPen)
    GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Draw", $hGUI)
    GUISetOnEvent(-3, "_Exit")
    Do
    Until Not Sleep(1000)
EndFunc   ;==>_line

Func Draw()
    Local $aMC, $mxo, $myo
    $aMC = GUIGetCursorInfo($hGUI)
    Do
        GUISetCursor(0, 1, 0)
        $mxo = $aMC[0]
        $myo = $aMC[1]
        $aMC = GUIGetCursorInfo($hGUI)
        If $mxo <> $aMC[0] Or $myo <> $aMC[1] Then
            _WinAPI_DrawLine($hDC, $aMC[0], $aMC[1], $mxo, $myo)
            _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE)
            $mxo = $aMC[0]
            $myo = $aMC[1]
        EndIf
        Sleep(10)
    Until Not $aMC[2]
EndFunc

Func _Exit()
    _WinAPI_SelectObject($hDC, $obj_orig)
    _WinAPI_DeleteObject($hPen)
    _WinAPI_ReleaseDC(0, $hDC)
    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

×
×
  • Create New...