From Newsgroup: alt.comp.os.windows-11
Marion wrote:
It wasn't easy to write. But here it is all done and working for you!
Please improve, of course, so everyone benefits from every post you make.
UPDATE
While the aloha autohotkey script has been working beautifully by clicking
the VPN button every half second to keep VPN active, I wanted to put the
AHK shortcut into the taskbar so I was able to do that changing the TARGET.
FROM TARGET=C:\data\sys\ahk\alohavpn.ahk
TO TARGET="C:\Program Files\AutoHotkey\v2\AutoHotkey64.exe" "C:\data\sys\ahk\alohavpn.ahk"
In addition, I made some minor improvements between version 1p7 & 1p9.
But the major improvement to come will be to remove the bar that comes up
on top asking to "Upgrade to Premium". Note that it has no effect on the working of the browser but it just wastes real estate in the browser so
it's not a critical improvement to make, but it's likely fixed in the next update.
; C:\data\sys\ahk\alohavpn.ahk
; This is alohavpn.ahk v1p9
; This script automatically launches the Aloha VPN Browser,
; presses a button to clear browsing data, and continuously
; monitors the VPN shield icon by clicking it only if it¢s off
; (gray) to ensure the VPN stays enabled (blue) even if the
; browser window isn't the active window or if it's 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 it¢s 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 isn¢t stolen & the mouse doesn¢t 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 window¢s 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 isn¢t 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 xxx lines
; Wrapped the transparency calls in try/catch so they don¢t throw
; fatal errors if the window disappears.
; Added a double-check that the hwnd is still valid before
; calling WinSetTransparent.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 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) ---
#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
}
Sleep 3000
CoordMode "Mouse", "Client"
CoordMode "Pixel", "Client"
buttonX := 131
buttonY := 55
intervalMs := 500
blueHex := 0x5895F6
grayHex := 0xBEBEC4
tolerance := 30
SetTimer(ClickIfGray, intervalMs)
SetTimer(CheckAppRunning, 1000)
Return
; --- Functions ---
ClickIfGray(*) {
global buttonX, buttonY, grayHex, tolerance, appPid
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
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
}
}
avgColor := Round(total / count)
if IsColorClose(avgColor, grayHex, tolerance) {
MouseGetPos(&oldX, &oldY)
MouseMove(buttonX, buttonY, 0)
Click
MouseMove(oldX, oldY, 0)
}
}
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
}
CheckAppRunning(*) {
global appPid
if !WinExist("ahk_pid " appPid) {
SetTimer(ClickIfGray, 0)
SetTimer(CheckAppRunning, 0)
ExitApp
}
}
; End of C:\data\sys\ahk\alohavpn.ahk
--
In the United States we have a culture of doing whatever it is we want to
do, despite the fact that marketing outfits want to sell us their solution.
--- Synchronet 3.21a-Linux NewsLink 1.2