Does
wsconsctl keyboard.encoding=us
work?
If yes, put that in /etc/wsconsctl.conf
to make it persistent.
Or are you saying that that would only work for PS/2 keyboards? Maybe enabling USB legacy keyboard mode in the BIOS would help in that case?
wsconscfg -k
may also be of use.
Perhaps you need to change the device from
/dev/uhid0
to something like
/dev/wskbd0
or
/dev/wskbd1
I assume you're trying to do this in shell or similar (else, you'd just use the X libraries directly). If so, you may find xinput --test «device-name»
much easier to parse.
Unfortunately, it really isn't shell-scripting friendly. But you can make it work with stdbuf
. It runs until you kill it, but your shell script could pipe it to read
.
So, you can do something like this:
stty -echo
stdbuf -oL xinput test 'AT Translated Set 2 keyboard' \
| perl -nE 'BEGIN {$| = 1} m/^key press\s+(\d+)/ and say $1' \
| for key in q w e r t y; do
echo -n "Please press $key: "
read -r keycode
echo "key $key = $keycode"
done
stty echo
You will need to use the correct keyboard name in place of "AT Translated Set 2 keyboard". You can find it with xinput list
:
anthony@Zia:~$ xinput list
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ Logitech USB-PS/2 Optical Mouse id=8 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Power Button id=6 [slave keyboard (3)]
↳ Power Button id=7 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=9 [slave keyboard (3)]
Unfortunately, you have to use a specific device—you can't use the core keyboard.
(Also, you'll need to find a way to kill the xinput in the above, or just content yourself to hit Control-C when you've entered all the keys. And you'll probably want to list more keys than qwerty.)
Best Answer
Linux uses two independent keyboard mappings. One for the graphical mode X and one for the console.
You usually change the first one with
setxkbmap
(orxmodmap
) and the second one withloadkeys
. All those tool have a fine manpage.For
loadkeys
you can find the existing keymaps under/usr/share/kbd/keymaps
. The description of those files is available inman 5 keymaps
.