The following are 2 scripts...
One to determine the angle off the x-axis and
One to determine the angle off the y-axis.
Hopefully they are helpful to someone.
X-Axis
- X-Axis.png (5.04 KiB) Viewed 528 times
Spoiler
Code: Select all
;; Determine angle between two mouse clicks from horizontal x-axis.
#MaxThreadsPerHotkey 2
#NoEnv
#Persistent
#SingleInstance, Force
SetBatchLines -1
clickCount := 0 ;; Reset variables.
clickPoints := []
firstClickIgnored := false ;; Flag to ignore the first click.
MouseClickHandler: ;; If the first click has not been ignored yet, ignore this click.
if (firstClickIgnored) {
clickCount++
MouseGetPos, clickX, clickY
clickPoints[clickCount] := {x: clickX, y: clickY}
if (clickCount = 2) { ;; If two clicks have been recorded, calculate the angle.
x1 := clickPoints[1].x ;; Get the coordinates of the first and second click.
y1 := clickPoints[1].y
x2 := clickPoints[2].x
y2 := clickPoints[2].y
deltaX := x2 - x1 ;; Calculate the difference in coordinates.
deltaY := y2 - y1
angle := ATan(-deltaY / deltaX) ;; Calculate the angle in radians using horizontal x-axis as zero.
angleDegrees := angle * (180 / 3.141592653589793) ;; Convert the angle to degrees.
if (deltaX > 0 and deltaY < 0) { ;; Adjust the angle based on quadrant.
angleDegrees := Abs(angleDegrees) ;; First quadrant (0 to 90 degrees)
} else if (deltaX < 0) {
angleDegrees += 180 ;; Second and third quadrants (90 to 270 degrees)
} else if (deltaX > 0 and deltaY > 0) {
angleDegrees := 360 + angleDegrees ;; Fourth quadrant (270 to 360 degrees)
}
roundedAngle := Round(angleDegrees, 2) ;; Round the angle.
Tooltip, Angle: %roundedAngle%° ;; Display the angle in a tooltip.
Clipboard:= "Angle: "roundedAngle "°" ;; Copy angle to clipboard.
clickCount := 0 ;; Reset variables for next calculation.
clickPoints := []
SetTimer, RemoveTooltip, -3000 ;; Remove tooltip after 3 seconds.
}
} else {
firstClickIgnored := true
}
Return
^LButton::Gosub, MouseClickHandler ;; HOTKEY trigger.
Return
RemoveTooltip:
Tooltip
Return
Y-Axis
- Y-Axis.png (5.51 KiB) Viewed 528 times
Spoiler
Code: Select all
;; Determine angle between two mouse clicks from vertical y-axis.
#MaxThreadsPerHotkey 2
#NoEnv
; #NoTrayIcon
#Persistent
#SingleInstance, Force
SetBatchLines -1
clickCount := 0 ;; Reset variables.
firstClickIgnored := false ;; Flag to ignore the first click.
clickPoints := []
MouseClickHandler: ;; If the first click has not been ignored yet, ignore this click.
if (!firstClickIgnored) {
firstClickIgnored := true
return
}
clickCount++
MouseGetPos, clickX, clickY
clickPoints[clickCount] := {x: clickX, y: clickY}
if (clickCount = 2) { ;; If two clicks have been recorded, calculate the angle.
x1 := clickPoints[1].x ;; Get the coordinates of the first and second click.
y1 := clickPoints[1].y
x2 := clickPoints[2].x
y2 := clickPoints[2].y
deltaX := x2 - x1 ;; Calculate the difference in coordinates.
deltaY := y2 - y1
angle := ATan(deltaX / -deltaY) ;; Calculate the angle in radians using vertical y-axis as zero.
angleDegrees := angle * (180 / 3.141592653589793) ;; Convert the angle to degrees.
if (deltaY > 0) { ;; Adjust the angle based on quadrant.
angleDegrees += 180 ;; If the second point is below the first point.
} else if (deltaX < 0) {
angleDegrees += 360 ;; If the second point is to the left of the first point.
}
if (angleDegrees >= 360) { ;; Normalize the angle to 0-360 degrees.
angleDegrees -= 360
}
roundedAngle := Round(angleDegrees, 2) ;; Round the angle.
Tooltip, Angle: %roundedAngle%° ;; Display the angle in a tooltip.
Clipboard:= "Angle: "roundedAngle "°" ;; Copy angle to clipboard.
clickCount := 0 ;; Reset variables for next calculation.
clickPoints := []
SetTimer, RemoveTooltip, -3000 ;; Remove tooltip after 3 seconds.
}
Return
^LButton::Gosub, MouseClickHandler ;; HOTKEY trigger.
Return
RemoveTooltip:
Tooltip
Return