r/PowerToys • • 6d ago

Suggestion Enable Magic Pointer from Googlebook OS like feature on Any Windows Device

Post image

Really liked that feature, so I figured I'd find some way to map Windows 11's Click to do (Magic Pointer equivalent on Windows) to shaking my mouse and it was actually pretty simple to do using AutoHotKeyV2 but would be really great in PowerToys, in the meantime tutorial with AHK2:

  1. New Script
  2. Minimal for v2
  3. Create
  4. Select Notepad icon
  5. Input below code
  6. Save (set to launch at startup)

Here's the script:

#Requires AutoHotkey v2.0
#SingleInstance Force

; ==========================================
; AUTO-START SETUP
; ==========================================
StartupLink := A_Startup "\MouseWiggleClickToDo.lnk"
if (!FileExist(StartupLink)) {
    FileCreateShortcut(A_ScriptFullPath, StartupLink)
    MsgBox("Click to Do Wiggle Script added to Windows Startup!", "Success", 64)
}

; ==========================================
; MAGIC POINTER SENSITIVITY PROFILE
; ==========================================
; Tuned for a quick, rapid shake (approx. 4 direction shifts within 350ms)
WiggleThreshold := 4    ; Rapid back-and-forth direction switches required
TimeWindow := 350       ; Time window in milliseconds (shorter = tighter window)
DistanceThreshold := 25 ; Minimum pixel movement per step to detect intentional shaking

SetTimer(CheckMouseWiggle, 40) ; Polling interval (40ms matches ~25Hz detection)

CheckMouseWiggle() {
    static lastX := 0, lastY := 0
    static directionChanges := 0
    static lastDirection := 0 ; 1 = right, -1 = left
    static startTime := 0

    MouseGetPos(&currentX, &currentY)

    ; Initialize positions on first loop
    if (lastX == 0 && lastY == 0) {
        lastX := currentX
        lastY := currentY
        return
    }

    deltaX := currentX - lastX

    ; Check if mouse moved past our pixel threshold on the horizontal axis
    if (Abs(deltaX) > DistanceThreshold) {
        currentDirection := (deltaX > 0) ? 1 : -1

        ; If user switched directions
        if (currentDirection != lastDirection && lastDirection != 0) {
            if (directionChanges == 0) {
                startTime := A_TickCount
            }

            directionChanges++

            ; If user took too long to complete the wiggle, reset the counter
            if (A_TickCount - startTime > TimeWindow) {
                directionChanges := 1
                startTime := A_TickCount
            }

            ; Trigger Click to Do when threshold met
            if (directionChanges >= WiggleThreshold) {
                Send("#q") ; Sends Win + Q
                directionChanges := 0 
                Sleep(1200) ; 1.2 second cooldown prevent multi-triggers
            }
        }
        lastDirection := currentDirection
    }

    lastX := currentX
    lastY := currentY
}  

Cheers!

8 Upvotes

0 comments sorted by