Re: Tutorial: Vastly improving Aloha free VPN privacy using an AutoHotKey script
From
Marian@marianjones@helpfulpeople.com to
alt.comp.os.windows-10,alt.comp.os.windows-11,alt.comp.microsoft.windows on Sun Dec 21 17:42:45 2025
From Newsgroup: alt.comp.os.windows-11
UPDATE:
This is perfect now! It does everything we needed it to do with Aloha!
Now that we have the Aloha VPN browser working without constantly shutting
off the VPN, the only thing left was to also automatically click away
the fat wasted-space "VPN has disconnected" banner (which does nothing but take up space).
Using Window Spy for AHK, the distance to its "[x]Close" always seemed to
be the same number of pixels from the right edge of the Aloha browser
window, while the distance from the top edge to its "[x]Close" was always within a small range depending on the window length & width sizing.
This allowed me to improve the AHK script so that now when it notices the shield went to gray, it turns the shield blue first and then clicks away
the wasted-space banner by finding * tapping the center of the closing (X).
; C:\data\sys\ahk\alohavpn.ahk
; This is alohavpn.ahk v2p0
; This script automatically launches the Aloha VPN Browser,
; which is set to open only one tab to this web page
; aloha://settings/clearBrowserData
; so the user presses the button to clear browsing data, and
; then this script continuously monitors the VPN shield icon
; by clicking it only if itos off (gray)
; to ensure the VPN stays enabled (blue)
; even if the browser window isn't the active window
; and even if the browser window is behind others.
; Behavior: C:\Program Files\AutoHotkey\v2\AutoHotkey64.exe
; 1) Opens Aloha browser
; 2) Clicks VPN (gray) shield icon to enable it (blue);
; 3) Then periodically checks the shield x:y location 140:53;
; 4) If the shield is gray (off), click it; if blue (on), do nothing.
; Notes:
; Limit on comment line length is .......................................
; Coordinates are relative to the Aloha window (CoordMode "Window").
; The origin (0,0) is the window top-left corner (incl title/borders).
; The X increases to the right; the Y increases downward.
; Works regardless of which monitor the window is on or where itos moved.
; Works regardless of window size.
; Works on the window regardless if it's active (current focus) or not.
; Use Window Spy to confirm pixel colors and window-relative coordinates.
; Clicks use ControlClick so focus isnot stolen & the mouse doesnot move.
; This TARGET works as a shortcut but it can't be pinned to the taskbar:
; TARGET=C:\data\sys\ahk\alohavpn.ahk
; This Windows shortcut TARGET can be pinned to the taskbar:
; "C:\Program Files\AutoHotkey\v2\AutoHotkey64.exe" "C:\data\sys\ahk\alohavpn.ahk"
; Versions
; v1p0 20250910 59 lines
; Launches the freeware Aloha VPN Browser [Version 4.9.0.0 (64-bit)]
; Set the shortcut TARGET = C:\data\sys\ahk\aloha_vpn.ahk
; This script runs Aloha which opens to clearBrowserData
; <aloha://settings/clearBrowserData>
; This script taps the "Clear data" button on bottom right
; Then it taps the VPN shield at top to turn the shield on automatically
; v1p1 20251016 68 lines
; Taps the shield icon every 30 seconds
; The probem is that it toggles it off if it had been toggled on
; v1p2 20251016 75 lines
; Use "C:\Program Files\AutoHotkey\WindowSpy.ahk" to get the color
; Click 601, 68 ; this is in the blue/gray part (5895F6/BEBEC4)
; v1p3 20251016 142 lines
; If gray, tap it. If blue, don't tap it.
; Colors from Window Spy (hex RRGGBB)
; blueHex := 0x5895F6
; grayHex := 0xBEBEC4
; tolerance := 30 ; adjust if needed (0-441)
; ControlClick without moving the visible mouse (no flicker)
; v1p4 20251016 148 lines
; Changed the time period from 30 seconds to 1 second
; 30 seconds = 30000, 1 second = 1000
; v1p5 20251016 127 lines
; Cleaned up comments
; v1p6 20251016 161 lines
; Changed hard-coded path to aloha.exe to be independent of user
; Added detection of run failure for a more robust watcher
; v1p7 20251017 175 lines
; Removed the clear-cookies click to simplify the script.
; Added the ability to monitor the shield no matter where it is.
; Changed x:y coordinates relative to the screen top-left origin
; to x:y (140:53) coordinates relative to the window top-left origin.
; Screen: 602, 67, Window: 140, 53
; No matter where the Aloha window is on the monitor, the shield
; icon will always be at (140,53) relative to the windowos origin.
; Client: 132, 53 (default) (i.e., main monitor)
; Color: 5895F6 (Red=58 Green=95 Blue=F6) (blue)
; Active windows position
; Screen: x: 462 y: 14 w: 910 h: 1060
; Client: x: 470 y: 14 w: 894 h: 1052
; The shield icon is always (139,54) relative to window origin
; (or (131,54) in client coordinates).
; Aloha isnot repainting shield icon when the window is unfocused.
; so we need to force a tiny "change" in aloha to repaint pixels.
; v1p8 20251020 189 lines
; Cleaned up the debugging commands
; v1p9 20251104 178 lines
; Wrapped the transparency calls in try/catch so they donot throw
; fatal errors if the window disappears.
; Added a double-check that the hwnd is still valid before
; calling WinSetTransparent.
; v2p0 20251221 223 lines
; add code to close the banner that pops up when the blue shield
; turns to gray randomly (every few minutes or so) saying:
; "VPN has been disconnected. For basic accounts, VPN works only
; in Aloha Broser. Upgrade to Premium to protect your whole computer.
; (Upgrade to Premium)(Not now)(x)Close"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Step 1: Launch Aloha VPN Browser and capture its PID
; The new instance replaces older running instances sans prompting.
; --- Aloha VPN Auto-Enable Script (fixed) ---
; --- ALOHA LAUNCH BLOCK START ---
#SingleInstance Force
localAppData := EnvGet("LOCALAPPDATA")
exePath := localAppData . "\Aloha Mobile\Aloha\Application\aloha.exe"
if !FileExist(exePath) {
MsgBox "Aloha executable not found:`n" exePath
ExitApp
}
Run(exePath)
if !WinWait("ahk_class Chrome_WidgetWin_1", , 10) {
MsgBox "Aloha started but no window appeared within 10s."
ExitApp
}
appPid := WinGetPID("ahk_class Chrome_WidgetWin_1")
if !appPid {
MsgBox "Could not determine Aloha PID after launch."
ExitApp
}
; --- ALOHA LAUNCH BLOCK END ---
Sleep 3000
CoordMode "Mouse", "Client"
CoordMode "Pixel", "Client"
; --- GLOBAL VARIABLES BLOCK START ---
buttonX := 131
buttonY := 55
intervalMs := 500
blueHex := 0x5895F6
grayHex := 0xBEBEC4
tolerance := 30
; --- v2p0 banner close button offsets (relative to client area) ---
closeRightOffset := 30
closeTopOffset := 82
; --- GLOBAL VARIABLES BLOCK END ---
; --- TIMERS SETUP BLOCK START ---
SetTimer(ClickIfGray, intervalMs)
SetTimer(CheckAppRunning, 1000)
Return
; --- TIMERS SETUP BLOCK END ---
; --- CLICKIFGRAY FUNCTION START ---
ClickIfGray(*) {
global buttonX, buttonY, grayHex, tolerance, appPid
global closeRightOffset, closeTopOffset
hwnd := WinExist("ahk_pid " appPid)
if !hwnd || !WinExist("ahk_id " hwnd)
return
; Safely toggle transparency to force repaint
try {
WinSetTransparent(254, "ahk_id " hwnd)
WinSetTransparent("OFF", "ahk_id " hwnd)
} catch {
return
}
; Sample a 3x3 area around the shield pixel
; --- SHIELD COLOR SAMPLING START ---
total := 0, count := 0
for dx in [-1, 0, 1] {
for dy in [-1, 0, 1] {
x := buttonX + dx
y := buttonY + dy
color := PixelGetColor(x, y, "RGB")
total += color
count += 1
}
}
; --- SHIELD COLOR SAMPLING END ---
avgColor := Round(total / count)
if IsColorClose(avgColor, grayHex, tolerance) {
; --- SHIELD CLICK LOGIC START ---
; This clicks the gray shield to re-enable VPN & turn it blue
MouseGetPos(&oldX, &oldY)
MouseMove(buttonX, buttonY, 0)
Click
MouseMove(oldX, oldY, 0)
; --- SHIELD CLICK LOGIC END ---
; --- v2p0 BANNER CLOSE LOGIC START ---
; v2p0: close the VPN-disconnected banner (simple method)
WinGetClientPos(&cx, &cy, &cw, &ch, "ahk_id " hwnd)
closeX := cw - closeRightOffset
closeY := closeTopOffset
MouseGetPos(&old2X, &old2Y)
MouseMove(closeX, closeY, 0)
Click
MouseMove(old2X, old2Y, 0)
; --- v2p0 BANNER CLOSE LOGIC END ---
}
}
; --- CLICKIFGRAY FUNCTION END ---
; --- ISCOLORCLOSE FUNCTION START ---
IsColorClose(c1, c2, tol) {
r1 := (c1 >> 16) & 0xFF, g1 := (c1 >> 8) & 0xFF, b1 := c1 & 0xFF
r2 := (c2 >> 16) & 0xFF, g2 := (c2 >> 8) & 0xFF, b2 := c2 & 0xFF
dist := Sqrt((r1 - r2)**2 + (g1 - g2)**2 + (b1 - b2)**2)
return dist <= tol
}
; --- ISCOLORCLOSE FUNCTION END ---
; --- CHECKAPPRUNNING FUNCTION START ---
CheckAppRunning(*) {
global appPid
if !WinExist("ahk_pid " appPid) {
SetTimer(ClickIfGray, 0)
SetTimer(CheckAppRunning, 0)
ExitApp
}
}
; --- CHECKAPPRUNNING FUNCTION END ---
; End of C:\data\sys\ahk\alohavpn.ahk
--
Everything is possible if you're intelligent, but it's not always worth it. What makes it worth it, sometimes, is helping others do what you can do.
--- Synchronet 3.21a-Linux NewsLink 1.2