External Keyboard Disable/Enable
Hello!
I'm wondering if anyone knows of a clear programmatic way to disable and re-enable an externally plugged in USB keyboard to a Raspberry Pi 5 running Bookworm 64bit PiOS.
Ultimately, the goal is to have control at any given point for whether the keyboard is enabled or not - ideally through a shell command or something of that nature. Kind of similar to an equivalent of clicking the keyboard lock key that some laptop keyboards will have.
Thank you in advance for any insight! I've done some searching around and found some external packages that potentially could be of use but I figured I'd ask this community first for if there is a straightforward way that would work :)
(also apologies if this is posted into the wrong section of this forum - I wasn't quite sure where this fit into)
I'm wondering if anyone knows of a clear programmatic way to disable and re-enable an externally plugged in USB keyboard to a Raspberry Pi 5 running Bookworm 64bit PiOS.
Ultimately, the goal is to have control at any given point for whether the keyboard is enabled or not - ideally through a shell command or something of that nature. Kind of similar to an equivalent of clicking the keyboard lock key that some laptop keyboards will have.
Thank you in advance for any insight! I've done some searching around and found some external packages that potentially could be of use but I figured I'd ask this community first for if there is a straightforward way that would work :)
(also apologies if this is posted into the wrong section of this forum - I wasn't quite sure where this fit into)
- cillian64
- Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator - Posts: 115
- Joined: Tue Sep 26, 2023 8:49 am
Re: External Keyboard Disable/Enable
Hello again. I had a quick look around and found a slightly hacky way. First, `sudo apt install evtest`. Then use `libinput list-devices` to find out which input device is your keyboard, in my case it's `/dev/input/event0`. Beware that this will probably change if the device reboots or if the keyboard is unplugged/replugged, so you probably need to write a script to automatically parse out the device. Then, to disable the keyboard run `evtest --grab /dev/input/event0 >/dev/null 2>&1` (substituting in your device). To re-enable the keyboard just kill evtest.
labwc does have a builtin mechanism for disabling mice/trackpads, but sadly it doesn't work with keyboards.
Here's a one-liner which works for me to find the keyboard device and grab it, you'll need to replace the device name if it's not an official Pi keyboard
labwc does have a builtin mechanism for disabling mice/trackpads, but sadly it doesn't work with keyboards.
Here's a one-liner which works for me to find the keyboard device and grab it, you'll need to replace the device name if it's not an official Pi keyboard
Code: Select all
evtest --grab $(libinput list-devices | grep -A1 'RPI Wired Keyboard 1' | grep Kernel | head -n1 | tr -s " " | cut -d' ' -f2) >/dev/null 2>/dev/null- cillian64
- Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator - Posts: 115
- Joined: Tue Sep 26, 2023 8:49 am
Re: External Keyboard Disable/Enable
There is a nicer way to do this using labwc config, but a bug meant it doesn't work in the current labwc release. I've just submitted a fix so this will be available in a future labwc release: https://github.com/labwc/labwc/pull/3208
Re: External Keyboard Disable/Enable
Hello!
Sorry for my delayed reply, and thank you so much for your thoughtful response as always.
I appreciate the insight into using evtest, and good news about the labwc! That looks great. The initiative is much appreciated!
Thank you,
Julia
Sorry for my delayed reply, and thank you so much for your thoughtful response as always.
I appreciate the insight into using evtest, and good news about the labwc! That looks great. The initiative is much appreciated!
Thank you,
Julia
Jump to
- Community
- General discussion
- Announcements
- Other languages
- Deutsch
- Español
- Français
- Italiano
- Nederlands
- 日本語
- Polski
- Português
- Русский
- Türkçe
- User groups and events
- Raspberry Pi Official Magazine
- Using the Raspberry Pi
- Beginners
- Troubleshooting
- Advanced users
- Assistive technology and accessibility
- Education
- Picademy
- Teaching and learning resources
- Staffroom, classroom and projects
- Astro Pi
- Mathematica
- High Altitude Balloon
- Weather station
- Programming
- C/C++
- Java
- Python
- Scratch
- Other programming languages
- Windows 10 for IoT
- Wolfram Language
- Bare metal, Assembly language
- Graphics programming
- OpenGLES
- OpenVG
- OpenMAX
- General programming discussion
- Projects
- Networking and servers
- Automation, sensing and robotics
- Graphics, sound and multimedia
- Other projects
- Media centres
- Gaming
- AIY Projects
- Hardware and peripherals
- Camera board
- Compute Module
- Official Display
- HATs and other add-ons
- Device Tree
- Interfacing (DSI, CSI, I2C, etc.)
- Keyboard computers (400, 500, 500+)
- Raspberry Pi Pico
- General
- SDK
- MicroPython
- Other RP2040 boards
- Zephyr
- Rust
- AI Accelerator
- AI Camera - IMX500
- Hailo
- Software
- Raspberry Pi OS
- Raspberry Pi Connect
- Raspberry Pi Desktop for PC and Mac
- Beta testing
- Other
- Android
- Debian
- FreeBSD
- Gentoo
- Linux Kernel
- NetBSD
- openSUSE
- Plan 9
- Puppy
- Arch
- Pidora / Fedora
- RISCOS
- Ubuntu
- Ye Olde Pi Shoppe
- For sale
- Wanted
- Off topic
- Off topic discussion