# Amateur here, I'm trying to get a shape to point at my mouse and I can't figure it out. my code is below and any help would be appreciated. • ### Question

• GraphicsWindow.Clear()
GraphicsWindow.Top = 0
GraphicsWindow.Left = 0
GraphicsWindow.Width = Desktop.Width
GraphicsWindow.Height = Desktop.Height
pointerx = GraphicsWindow.Width / 2
pointery = GraphicsWindow.Height / 2
Shapes.Move(pointer,pointerx,pointery)
Shapes.Move(marker,pointerx,pointery)
While 1=1
linea = math.SquareRoot(math.Power(Math.Max(pointerx,mouse.MouseX) - Math.Min(pointerx,mouse.MouseX),2) + math.Power(Math.Max(pointery,mouse.Mousey) - Math.Min(pointery,mouse.Mousey),2))
lineb = math.SquareRoot(math.Power(Math.Max(pointerx,mouse.MouseX) - Math.Min(pointerx,mouse.MouseX),2) + math.Power(pointery, 2))
If Mouse.MouseX < pointerx Or Mouse.MouseY < pointery Then
multiplier = 1
Else
multiplier = -1
endif
angle = Math.Min(lineb,linea) / Math.Max(lineb,linea)
angle = math.ArcSin(angle)
angle = angle * 100
angle = angle * multiplier
TextWindow.WriteLine(angle)
Shapes.Rotate(pointer,angle)
endwhile
Wednesday, December 18, 2019 2:03 PM

• Hi,

maybe like this (hope the comment help)

GraphicsWindow.Top = 0
GraphicsWindow.Left = 0
GraphicsWindow.Width = Desktop.Width
GraphicsWindow.Height = Desktop.Height
'Display the marker on top of the pointer
'Center shapes (top left(right) is center - 0.5(width(height)
pointerx = GraphicsWindow.Width / 2
pointery = GraphicsWindow.Height / 2
Shapes.Move(pointer,pointerx-5,pointery-10)
Shapes.Move(marker,pointerx-2.5,pointery-2.5)
While 1=1
'Use GW.mouseX/Y since these are relative to GW coordinates and there is not device dpi scaling
mx = GraphicsWindow.MouseX
my = GraphicsWindow.MouseY
'vector from marker to Mouse
dx = mx-pointerx
dy = my-pointery
If (dx = 0) Then
angle = Math.Pi/2
Else
angle = Math.ArcTan(dy/dx)
EndIf
'Make sure we are in the right quadrant
If (dx < 0) Then
angle = angle+Math.Pi
EndIf
'Convert to degrees
angle = Math.GetDegrees(angle)
'Make the short side the pointer - wouldn't need to do this if long side was width
angle = angle+90
'Rotatate pointer
Shapes.Rotate(pointer,angle)
EndWhile

Wednesday, December 18, 2019 7:30 PM