We use some essential cookies to make our website work.

We use optional cookies, as detailed in our cookie policy, to remember your settings and understand how you use our website.

4 posts • Page 1 of 1
julia!
Posts: 15
Joined: Mon Sep 15, 2025 8:18 pm

External Keyboard Disable/Enable

Fri Nov 07, 2025 5:55 pm

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)

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

Mon Nov 10, 2025 11:24 am

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

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

Thu Nov 13, 2025 2:12 pm

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

julia!
Posts: 15
Joined: Mon Sep 15, 2025 8:18 pm

Re: External Keyboard Disable/Enable

Thu Nov 13, 2025 8:48 pm

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

4 posts • Page 1 of 1

Return to "Raspberry Pi OS"

AltStyle によって変換されたページ (->オリジナル) /