Draw horizontal screen wide cross at cursor

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
locked21
Posts: 4
Joined: 07 Jul 2022, 14:52

Draw horizontal screen wide cross at cursor

20 May 2023, 18:08

Like the title says, I would like a script that shows a screen wide cross, centered at the current mouse position. The cross would be a thin vertical black line and a thin horizontal black line. I could not find a function that draws in the documentation...
User avatar
boiler
Posts: 17393
Joined: 21 Dec 2014, 02:44

Re: Draw horizontal screen wide cross at cursor

20 May 2023, 22:43

Here's an approach. You didn't specify the height, so I made it the height of the screen.

Code: Select all

#Requires AutoHotkey v2.0
CoordMode "Mouse", "Screen"
HGui := Gui("+ToolWindow -Caption")
HGui.BackColor := "Black"
HGui.Show("w" A_ScreenWidth " h1")
VGui := Gui("+ToolWindow -Caption")
VGui.BackColor := "Black"
VGui.Show("w1 h" A_ScreenHeight)
SetTimer MoveCross, 20
return

MoveCross() {
	MouseGetPos &mX, &mY
	HGui.Move(, mY)
	VGui.Move(mX)	
}
xroot
Posts: 41
Joined: 21 Jun 2019, 08:45

Re: Draw horizontal screen wide cross at cursor

21 May 2023, 08:24

@locked21
Here is my take on what you want. It works on any window that is open.

Code: Select all


#SingleInstance

CoordMode "Mouse"
SetWinDelay 0

Cross_Hairs(cHairs){
    win           := Gui("-DPIScale -caption +AlwaysOnTop +E32")
    win.BackColor := "black"
    win.Show cHairs
    WinSetTransparent 255,win.hWnd
    Return win
}

MouseGetPos &x,&y

LineSize := 4

xwin := Cross_Hairs("x0 y" y "w" A_ScreenWidth "h" LineSize)
ywin := Cross_Hairs("x" x "y0 w" LineSize "h" A_ScreenHeight)  

Loop {
    MouseGetPos &x,&y
    ywin.Move x
    xwin.Move ,y
    Sleep 0
}

Esc::ExitApp


Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: mikeyww, moltenchees and 56 guests