DEV Community

Cover image for Windows won't let you own Win+Shift+S. So I hooked the keyboard in Python.

Windows won't let you own Win+Shift+S. So I hooked the keyboard in Python.

Akhouri Anmol Kumar on November 07, 2026

I wanted one small thing: press Win+Shift+S and get my own screenshot tool instead of Snipping Tool. That turned into a 7,600-line Python project,...
Collapse
 
star123 profile image
Sᴛᴀʀ⭐ •

❤️

Collapse
 
akhourianmolkumar profile image
Akhouri Anmol Kumar •

thanks star for comment
what about your channel?

Collapse
 
star123 profile image
Sᴛᴀʀ⭐ •

After Diwali 😀

Thread Thread
 
akhourianmolkumar profile image
Akhouri Anmol Kumar •

oh okay channel name StarDev?

Thread Thread
 
star123 profile image
Sᴛᴀʀ⭐ •

Idk yet. Bro please share your github link.😀

Thread Thread
 
akhourianmolkumar profile image
Akhouri Anmol Kumar •
Collapse
 
pengeszikra profile image
Peter Vivo •

Good to remember how can we will solve this kind of promblems! ✌️
I always fight with windows keyboard settings ( forced company laptop ) until I give up the fight. My trick: I use AutoHotkey program to redefine my keyboard to
capsLock + ; = é
capsLock + ' = á
... and so on
Because my main problem is the hungarian languge special character. In chat with my hungarian collegues I like to use full hungarian char set, but I always use english keyboard set and really hate to install multiple language keyboard set because windows do not saw which keyboard currently use, plus many program using english keyboard shortkeys. The whole question is so anoying.

Collapse
 
amintacccp profile image
tamina •

The 0xE8 virtual-key injection is the detail that would have taken me days to find — swallowing S and then watching Start open on Win release is exactly the kind of bug that only shows up in real use. Same for the callback getting garbage-collected with no traceback. And stating outright that the hook only watches the keys it cares about, with nothing logged or stored, is the right call for a keyboard hook. Really nice write-up.

Collapse
 
akhourianmolkumar profile image
Akhouri Anmol Kumar •

Thanks 😊

Collapse
 
amintacccp profile image
tamina •

You're welcome — and thanks again for the write-up, the callback GC gotcha alone was worth the read. 😊

Collapse
 
sameerqaiser17 profile image
Sameer Qaiser •

The line that hit me: "If HOOKPROC(cb) gets garbage-collected, your app crashes on the next keypress. There's no traceback, it just dies."

That is genuinely the scariest sentence in Python. I'm relatively new to Python, and the silent failures are what keep me up at night—just a flash of a console and then nothing.

The fact that you built a 7,600-line Win32 API app in pure Python is wild. The WASAPI loopback and the Windows OCR workarounds are incredibly useful. I tried recording system audio in Python once, hit a wall with sounddevice, and gave up.

Quick question: what was the biggest headache when packaging this into a .exe with PyInstaller? Did you have to do a lot of custom hooking to include the ffmpeg binaries and the PowerShell OCR scripts?

Massive respect for seeing this through to the end.

Collapse
 
koda2026 profile image
Harun - solo dev •

Bro please change profile pic 🖼️ 🤣

Collapse
 
akhourianmolkumar profile image
Akhouri Anmol Kumar •

why 😂 I know I look joker but still bro I want that me and akhouri systems both visible in profile hehehe but any more cool idea?

Collapse
 
technogamerz profile image
𝐓𝐡𝐞 𝐋𝐚𝐳𝐲 𝐆𝐢𝐫𝐥 • • Edited

You changed your profile image! Wow!! :D

Collapse
 
akhourianmolkumar profile image
Akhouri Anmol Kumar •

is that profile pic looking good?

Collapse
 
enoch_hou profile image
Enoch Hou •

把钩子、回收站删除和原子写入这些小细节都写出来了,读起来很过瘾,收藏了。

Collapse
 
mp3sss31 profile image
mp3sss •

This is exactly the gap we hit from the Electron side: globalShortcut.register wraps RegisterHotKey, which silently returns false on any Win+ chord the shell has reserved — so Win+Shift+S is genuinely unreachable from main without a native module that drops to WH_KEYBOARD_LL. The two pitfalls you called out map directly to Electron main-process work too: keeping the HOOKPROC callback referenced at module scope is the same rule as keeping a Tray object — let it GC and the next keypress takes the process down with no stack. The 0xE8 trick to mark Win as 'used in a combo' is the kind of shell-internals detail the docs never mention and that every low-level-hook port eventually rediscovers.

Collapse
 
onelifevibe profile image
OneLifeVibe •

The 0xE8 virtual-key injection was the detail I would never have found on my own — swallowing S but leaving Win to open the Start menu on release is exactly the kind of bug that looks like the code is haunted. The HOOKPROC garbage-collection gotcha is the other one: a crash with no traceback is brutal to debug, so keeping the callback alive and making the hook decision unit-testable is a really nice touch. I also liked the discipline of recording the mic and loopback to separate WAVs and mixing with ffmpeg amix afterwards instead of fighting two drifting clocks in real time. Did the built-in Windows.Media.Ocr hold up on low-contrast screenshots, or is that where you reach for a fallback?