Goal
I'm trying to build a minimal working system where pressing a key in AutoHotkey (AHK) sends a message to a Chrome Extension, via a Python native messaging host.
The architecture is:
AHK → Named Pipe → Python (native host) → Chrome Extension (Manifest V3)
The end goal is simple: pressing a hotkey (like NumpadAdd) should trigger an event inside my extension.
What's Working
- ✅ AHK opens the named pipe
\\.\pipe\NativeEventPipeand writes JSON. - ✅ Python (native host) receives the AHK message via
win32pipe.ReadFile(...). - ✅ Python logs the message and calls
sys.stdout.buffer.write(...) + flush()to send to Chrome. - ✅ Chrome connects to the host and sends a handshake (
{ cmd: "start", attempt: 1 }). - ❌ Chrome never receives the AHK event.
onMessagenever fires after the handshake.
Everything below the native messaging boundary works — the AHK input is reaching Python. But Chrome doesn’t see the message sent from the native host.
Python Snippet (Native Host)
def send_message(message):
try:
encoded = json.dumps(message).encode("utf-8")
sys.stdout.buffer.write(struct.pack("I", len(encoded)))
sys.stdout.buffer.write(encoded)
sys.stdout.buffer.flush()
return True
except Exception as e:
# logs error
return False
Extension Snippet
port = chrome.runtime.connectNative("com.nativebridge.test");
port.onMessage.addListener((msg) => {
console.log("✅ [SW] AHK Event:", msg);
});
What I’m Looking For
❓ Can someone help me complete this system successfully?
I’m not committed to named pipes — I just want a minimal working solution where:
- AHK triggers an event
- That event is seen by the Chrome extension
- Native messaging is used in some form (pipe/file/stdin/etc.)
Also:
- ❓ Is my use of
sys.stdout.buffer.write(...)correct in this IPC model? - ❓ Is the pipe model fundamentally flawed when combined with
stdionative messaging? - ❓ Would a cleaner design (like invoking a short-lived subprocess from AHK) be more reliable?
Files & Repo
I've constructed a mostly minimal version of the project and made it public on github: https://github.com/ModifiedFootage/AhkNativeBridge
System
- Windows 11 Pro
- Brave Browser (Chromium)
- Chrome Extension (Manifest V3, service worker)
- AutoHotkey v1
- Python 3.11
- Using
win32pipe,win32filefor pipe access
Thanks in advance for any help on either finishing the system or improving the architecture.