adafruit / adafruit/Adafruit_CircuitPython_HID
keyboard_layout.write issues on linux
- Dominant language
- Python
- Stars
- 464
- Forks
- 121
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
I have some code that works as expected on Windows but does not send the keystrokes that I supply on Linux. Here's my code.py:
```py
import time
import board
import digitalio
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
def configure_pin(pin):
key_pin = digitalio.DigitalInOut(pin)
key_pin.direction = digitalio.Direction.INPUT
key_pin.pull = digitalio.Pull.UP
return key_pin
key_configurations = [
{
"pin": configure_pin(board.GP27),
"macro": "/time set day\n",
"pressed": False,
},
{
"pin": configure_pin(board.GP26),
"macro": "/time set night\n",
"pressed": False,
},
{
"pin": configure_pin(board.GP28),
"macro": "/tp 500 57 -53\n",
"pressed": False,
},
]
time.sleep(1) # Sleep for a bit to avoid a race condition on some systems
keyboard = Keyboard(usb_hid.devices)
keyboard_layout = KeyboardLayoutUS(keyboard) # We're in the US :)
while True:
# Check each pin
for config in key_configurations:
if not config["pin"].value: # Is it grounded?
# print("Pin #%d is grounded." % i)
if not config["pressed"]:
keyboard_layout.write(config["macro"], 0.05) # ...Print the string
config["pressed"] = True
else:
# print("Pin #%d is ungrounded." % i)
config["pressed"] = False
time.sleep(0.05)
```
According to dmesg and LSUSB, it looks like the keyboard is recognized as a HID device, but the key strokes are not sending for some reason. This code works fine on Windows. I am using Linux Mint.
Any ideas on troubleshooting?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the code.py example and reproduce the keyboard_layout.write call on Linux Mint, then compare the dmesg and LSUSB results with the reported Windows behavior. The issue is done when the supplied keystrokes work on Linux or the project documents a confirmed Linux limitation and its troubleshooting evidence.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- linux, python
- Domain
- embedded-iot, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100