After the main problem is solved try to read from multiple HID inputs I open here a new question for the following (and different) problem:
I installed minibian on a RaspPi. The entire system is running on 'de_DE'
, in details:
root@ddpi:~# locale
LANG=de_DE.UTF-8
LANGUAGE=
LC_CTYPE="de_DE.UTF-8"
LC_NUMERIC="de_DE.UTF-8"
LC_TIME="de_DE.UTF-8"
LC_COLLATE="de_DE.UTF-8"
LC_MONETARY="de_DE.UTF-8"
LC_MESSAGES="de_DE.UTF-8"
LC_PAPER="de_DE.UTF-8"
LC_NAME="de_DE.UTF-8"
LC_ADDRESS="de_DE.UTF-8"
LC_TELEPHONE="de_DE.UTF-8"
LC_MEASUREMENT="de_DE.UTF-8"
LC_IDENTIFICATION="de_DE.UTF-8"
LC_ALL=
and
root@ddpi:~# grep -v ^# /etc/locale.gen
de_DE.UTF-8 UTF-8
and also python locale.getdefaultlocale()
says 'de_DE','utf-8'
.
There is no X running (because it's not installed):
ps -aux | grep X
says 1297 0.0 0.1 4212 1828 pts/0 S+ 10:13 0:00 grep X
and systemctl get-default
says multi-user.target
.
But there is the following problem: I have a German keyboard connected, which writes german as expected in console, but is recognized as english from evdev. I am using these scripts, read input from usb keyboard in linux in combination with reading events from multiple devices which works as expected, except the language. My Y
keystroke is recognized as KEY_Z
, my Z
keystroke as KEY_Y
, my ß
as KEY_MINUS
and so on. But everything, so far I can see, is set to de_DE
.
This script (the evdev part only)
from evdev import InputDevice, categorize, ecodes
dev = InputDevice('/dev/input/event0')
print(dev)
#device /dev/input/event1, name "Dell Dell USB Keyboard", phys "usb-0000:00:12.1-2/input0"
for event in dev.read_loop():
if event.type == ecodes.EV_KEY:
print(categorize(event))
says
key event at 1510568613.966220, 44 (KEY_Z), down
key event at 1510568614.039341, 44 (KEY_Z), up
key event at 1510568614.926334, 21 (KEY_Y), down
key event at 1510568614.998331, 21 (KEY_Y), up
key event at 1510568615.799577, 12 (KEY_MINUS), down
key event at 1510568615.863569, 12 (KEY_MINUS), up
for yzß
keystrokes.
What's wrong here ?
So. According my own suggestion to create a german keyboard mapping here are my two scripts, which are still DEV VERSIONS, not yet in production, but work correctly on console output. The first one I named
hidraw_survey.py
because it is wondering all the time, if new HIDs are connected or unplugged. Both events cause apkill -f
and restart of the second scriptread_hidraw_scanner.py
, which handles the keyboard events of all connected HIDs at once. As there are the following:Why the numerical keypad (last on list) is counted twice... no idea, but the input events are processed correctly.
Both scripts try to find out and guess the numbers of the input event connections between 0 and 9 and skip these numbers, on which the tests are not successful. The language specific mapping itself is realized by
LANG = locale.getdefaultlocale()[0].split('_')[0].upper()
which delivers meDE
.The first script
hidraw_survey.py
:The 2nd script
read_hidraw_scanner.py
:Both scripts are full of dents and wrinkles made by a python newbie like me, but I think with a bit of improvement and simplifications it's a really nice toy to tell the RaspPi something like config settings or password inputs or whatever (in my case a barcode scanner with alternative manual input in case of not readable barcode and a RFID reader for waiter/waitress authentification in restaurants)
The mapping covers all german keyboard keys including SHIFT and ALTGR (right ALT), not yet ALT (left ALT). But it doesn't work with accents like è or é or ñ, nor CAPSLOCK. Improvements are welcome.
UPDATE The output looks like that at the moment. One after the other, a scanned numeric barcode, an alphanumeric barcode, a keyboard input and the RDFID reader at last.