I made a big red button. When pushed, it locks my computer.
- Screw the retaining ring and washer to the big red button base through the hole of the lid, and attach the switch mechanism at the bottom.
- Drill a hole, slightly bigger than the USB cable (so around 3 mm in diameter) through the middle of the knockout circle on the side of the box.
- Thread the wire end of the PCSensor USB cable through the hole from the outside in.
- Leaving a reasonable amount of slack inside the box, tie a knot in the cable to catch the tension of any cable yanks. This is the least good way to do this, but the wires take only a simple open-closed signal and don't connect to anything delicate.
- Screw the two wire leads into the cable posts. I had to strip some of the outer wire to make it fit and inner wires to expose enough meta. It doesn't matter which wire is which.
- Close the box.
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.
- As root, create the file `/etc/udev/hwdb.d/99-redbutton.hwdb` with these contents:
- Rebuild the hwdb database:
sudo systemd-hwdb update sudo udevadm trigger
- Use your desktop shortcut settings to have F13 trigger whatever you want.
I used these instructions1 to create the file above. If that doesn’t work, it may be because your hardware doesn’t exactly match what I used.
- First, make sure that the button is wired up and the PCSensor cable is working. To test, use a program like xev to see if anything is typed when the button is pressed.
- See if your Bus, Vendor, Product are different from the provided hwdb script above.
And find the block that corresponds to your PCSensor cable. Clues to finding it:
$ cat /proc/bus/input/devices
- It's the last entry
- It's the only one with a cryptic Name
- It has the same Vendor ID, 413d.
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
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.
- See if your keycode is different. Using the
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 ------------
- If it still isn't working, go to yulistic's instructions and start at the top.
Bill of Materials
|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.