I made a big red button. When pushed, it locks my computer.
The PCSensor cable comes with a Windows program to reprogram which key is sent when the cable circuit is closed. If you have Windows and this program works for you, program the cable to whatever button combo locks your screen, which for Windows is ⊞-L (Windows key-L). You are now done with this project.
If you can reprogram the button in Windows to Ctrl-Alt-L, you are done.
If you don’t have access to a Windows computer, or if the program fails to work, as it failed for me and for many people on the internet, read on to learn how to hack around this problem: For me, the cable types the letter
x whenever the circuit is closed, but it shouldn’t matter which letter it types; this hack will take any input from the device and produce the key stroke we want, which will be the F13 key. You almost certainly don’t have an F13 key on your keyboard, so we are free to map this key to anything we want. To do this, we need to intercept the signal from the PCSensor USB connection before it is transformed into a keystroke. We do this by creating a custom udev rule.
/etc/udev/hwdb.d/99-redbutton.hwdbwith these contents:
sudo systemd-hwdb update sudo udevadm trigger
And find the block that corresponds to your PCSensor cable. Clues to finding it:$ cat /proc/bus/input/devices
Compare the highlighted Bus, Vendor, and Product codes to the highlighted codes in the script, and change if necessary. Don't forget to rebuild the hwdb database before testing.I: Bus=0003 Vendor=413d Product=2107 Version=0111 N: Name="HID 413d:2107" P: Phys=usb-0000:04:00.0-2.1/input0 S: Sysfs=/devices/pci0000:00/0000:00:07.0/0000:04:00.0/usb10/10-2/10-2.1/10-2.1:1.0/0003:413D:2107.003E/input/input54 U: Uniq= H: Handlers=sysrq kbd mouse2 event7 leds js0 B: PROP=0 B: EV=12001f B: KEY=3007f 0 0 483ffef17aff32d bf54444600000000 ff000000070001 130c130b17c007 ffbf7bfad9415fff febeffdfffefffff fffefffffffffffe B: REL=103 B: ABS=100000003 B: MSC=10 B: LED=7
event#number from the previous command, do
sudo evtest /dev/input/event7. Push the big red button and get the value from the MSC_SCAN event:
Make sure this number matches the KEYBOARD_KEY_##### line in the hwdb file.Event: time 1537591591.694406, -------------- SYN_REPORT ------------ Event: time 1537591594.718043, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70005 Event: time 1537591594.718043, type 1 (EV_KEY), code 45 (KEY_X), value 1 Event: time 1537591594.718043, -------------- SYN_REPORT ------------
|PCSensor USB line switch cable||This was a reasonable at the price, even though the reprogramming program doesn't work.||$16|
|30mm Red Push Button box||This was worth it; it's a very nice box that I'll use for other projects. It will fit a Raspberry Pi Zero below the button.||$21|
|Plastic 30 mm Panel-Mount Push-Button Switch, Mushroom, Momentary||I way overspent on this button. It works fine but it's just plastic, and doesn't have an especially satisfying push-feel. If I needed another one, I would shop around for cheaper and springier/clickier.||$36|
Costs include tax and shipping.