From a9631892f0a3b44024094797574f43c9bf3e4180 Mon Sep 17 00:00:00 2001 From: TheBestPessimist Date: Tue, 7 Nov 2023 09:39:06 +0200 Subject: [PATCH] Midwork through Tippy2 --- AutoHotkey64.ahk | 6 ++++ lib/Tippy2.ahk | 90 ++++++++++++++++++++++++++++++++++++++++++++++-- lib/libdebug.ahk | 59 +++++++++++++++++++++++++++++-- 3 files changed, 150 insertions(+), 5 deletions(-) diff --git a/AutoHotkey64.ahk b/AutoHotkey64.ahk index 75e9fe4..59ba5b7 100644 --- a/AutoHotkey64.ahk +++ b/AutoHotkey64.ahk @@ -18,6 +18,11 @@ InstallMouseHook ; TraySetIcon "shell32.dll", 44 ; change tray icon to a yellow star TraySetIcon("resources/blueStar.ico") +CoordMode("Mouse", "Screen") + +; I removed `n and `t from hotstring trigger chars +; https://www.autohotkey.com/docs/v2/Hotstrings.htm#EndChars +#Hotstring EndChars -()[]{}:;'"/\,.?!`s ;; rest of everything #Include lib/Tippy.ahk @@ -34,6 +39,7 @@ TraySetIcon("resources/blueStar.ico") #Include *i Private.ahk +#Include lib/_JXON.ahk ;------------------------------------------------- diff --git a/lib/Tippy2.ahk b/lib/Tippy2.ahk index 059dec7..95ac0ee 100644 --- a/lib/Tippy2.ahk +++ b/lib/Tippy2.ahk @@ -81,6 +81,8 @@ class T ; offset from the previous tooltip (tooltip above) y += currentTooltipsHeights + ; if tooltip is at right side of screen +;TODO if(!tt.IsAlreadyShown()) { Tooltip( k . dbg(tt) " " currentTooltipsHeights, x, y, k) @@ -133,14 +135,52 @@ class T } +;GetMouseCoordinates????? +GetLocalScreenMouseCoordsAndBounds() { + screens := GetAllScreenCoordinates() + CoordMode("Mouse", "Screen") + MouseGetPos(&X, &Y) + for s in screens { + if (X >= s.Left && X <= s.Right && Y >= s.Bottom && Y <= s.Top) { + return {x: X - s.Left, y: Y - s.Top, screenHeight: s.Bottom, screenWidth: s.Right} + } + } +} -dbg(obj) -{ - return JxonEncode(obj, 1) +GetAllScreenCoordinates() { + static monitorCount := 0 + static screens := 0 + + newMonitorCount := MonitorGetCount() + if (monitorCount != newMonitorCount) { + monitorCount := newMonitorCount + + screens := [] + Loop MonitorCount { + MonitorGet A_Index, &L, &T, &R, &B + if (L > R) { + tmp := L + L := R + R := tmp + } + + if (B > T) { + tmp := B + B := T + T := tmp + } + screens.Push({Top: T, Bottom: B, Left: L, Right: R}) + } + } + return screens } + + + + ^j:: { Tippy("10 " A_Now, 1000000, 10) @@ -156,3 +196,47 @@ Tippy(text := "", durationMs := 3333, whichTooltip := 1) { T(text, durationMs, whichTooltip) } + + +^k:: +{ +MonitorCount := MonitorGetCount() +MonitorPrimary := MonitorGetPrimary() +MsgBox "Monitor Count:`t" MonitorCount "`nPrimary Monitor:`t" MonitorPrimary +Loop MonitorCount +{ + MonitorGet(1, &L, &T, &R, &B) + MonitorGetWorkArea A_Index, &WL, &WT, &WR, &WB + MsgBox + ( + "Monitor:`t#" A_Index " + Name:`t" MonitorGetName(A_Index) " + Left:`t" L " (" WL " work) + Top:`t" T " (" WT " work) + Right:`t" R " (" WR " work) + Bottom:`t" B " (" WB " work)" + ) +} +} + + + +class BB +{ + static v := 6 + + __New() + { + v := 1 ; ❌ assumes local variable, not the static + this.v := 1 ; ❌ assumes instance variable, not the static + BB.v := 1 ; ✅ + %this.__Class%.v :=1 ✅ + } + + showV() + { + Tooltip(v) ; ❌ Error: Warning: This variable appears to never be assigned a value. + Tooltip(BB.v) ; ✅ this works + Tooltip(this.V) ; ✅ this also works! 🎉 + } +} diff --git a/lib/libdebug.ahk b/lib/libdebug.ahk index e3ad6f5..6a1700e 100644 --- a/lib/libdebug.ahk +++ b/lib/libdebug.ahk @@ -1,15 +1,56 @@ #include +#Include _JXON.ahk +dbg(obj) +{ + return JxonEncode(obj, 1) +} ;------------------------------------------------ ; CapsLock + /: Toggle Mouse debugging mode CapsLock & /:: { static toggle := 0 MouseDebugging() + Tippy(dbg(GetAllMonitorsDimensions()), 1000000) SetTimer(MouseDebugging, (toggle := !toggle) ? 500 : 0) } MouseDebugging() { + MouseGetPos(&X, &Y) + Tippy("Mouse Pos: " x " x " y " (global)",, 18) + + VirtualScreenWidth := SysGet(78) + VirtualScreenHeight := SysGet(79) + Tippy("Screen Size: " VirtualScreenWidth " x " VirtualScreenHeight,, 19) + + + m := GetAllMonitorsDimensions() + Tippy(dbg(m),, 20) + for k, v in m { + if (X >= v.Left && X <= v.Right && Y >= v.Bottom && Y <= v.Top) { + return {x: X - v.Left, y: Y - v.Top} + } + } +} + +GetMouseCoordinatesInLocalScreen() { + MouseGetPos(&X, &Y) + m := GetAllMonitorsDimensions() + + for k, v in m { + if (X >= v.Left && X <= v.Right && Y >= v.Bottom && Y <= v.Top) { + return {x: X - v.Left, y: Y - v.Top} + } + } +} + +class LocalScreenMouseCoords { + x := "" + y := "" + +} + +MouseDebuggingOld() { CoordMode("Mouse", "Screen") MouseGetPos(&X, &Y) Tippy("Mouse Pos: " x " x " y " (global)", , 19) @@ -19,8 +60,9 @@ MouseDebugging() { Tippy("Screen Size: " VirtualScreenWidth " x " VirtualScreenHeight,, 18) localPos := GetLocalMonitorMouseCoords() - Tippy("Mouse Pos: " localPos.x " x " localPos.y " (local)",, 20) - + try { + Tippy("Mouse Pos: " localPos.x " x " localPos.y " (local)",, 20) + } } GetAllMonitorsDimensions() { @@ -34,6 +76,19 @@ GetAllMonitorsDimensions() { screens := [] Loop MonitorCount { MonitorGet A_Index, &L, &T, &R, &B + + if (L > R) { + tmp := L + L := R + R := tmp + } + + if (B > T) { + tmp := B + B := T + T := tmp + } + screens.Push({Top: T, Bottom: B, Left: L, Right: R}) } }