Why does the title say “research”? Because auto-unlock is really too hard, ( •̥́ ˍ •̀ू ). Had I not spent days looking things up, I really thought I could write it myself.
This post shares the approaches I imagined and the research results, so anyone interested later can see whether these pitfalls can be avoided. Following my own train of thought, from simple to complex, I’ll write out every approach I can think of.
Win32API Unlock
If you want to call an API to lock the screen, that’s really too easy:
1 | import ctypes |
LockWorkStation function official docs: to unlock, you must log in.
Typing the Password on the Lock Screen
Windows blocks keyboard simulation on the lock screen
I wrote a program and tried it myself: on the lock screen, sending commands to the computer to simulate input is not feasible — it only becomes usable after the user types the password to unlock.
Thinking further: a driver-level keyboard device — simulating a keyboard hardware device in Windows. I found this: Windows-driver-samples/input/kbfiltr/ — a keyboard filter device. But after experimenting for days I found I really couldn’t get this driver running; feasibility remains to be verified. Still, I don’t hold much hope.
Does Dynamic Lock Have an Inverse Operation
Dynamic lock auto-lock and auto-unlock problem — this is a question on the official site: Dynamic Lock can lock automatically but cannot unlock. Then I saw this:
Windows unlock with Windows Hello companion (IoT) devices
But note: Microsoft will deprecate the Windows Hello companion device framework API in 2020. This feature itself required special registration with Microsoft, and now the API is deprecated — what a fine follow-up stab.
Using the Phone’s Bluetooth to Simulate a Keyboard
This approach is similar to typing the password on the lock screen, because the bluetooth keyboards we normally use also work on the lock screen. If we could simulate the phone as a bluetooth input device, typing the password this way might achieve the effect.
I found this project: BLE-HID-Peripheral-for-Android, but on my own computer I could never succeed in making the phone act as an input device.
Another similar discussion: how to make an Android device act as an HID device — the firmware may need modification. Android doesn’t seem to have this feature yet; I hope it will, so phones’ bluetooth could simulate more devices.
Summary
I took this opportunity to also organize my thoughts from the past days: auto-unlocking Windows is really a troublesome thing. But there are other approaches, like fingerprint recognition — more and more laptops have fingerprint recognition; it’s cool and it achieves the function. Of course, auto-unlocking Windows was amateur research; discussion is welcome.
The possibly feasible approaches discussed above all require digging into the kernel or driver level — indeed somewhat difficult.