摘要 Abstract
本文记录笔者在安装Ubuntu时遇到的键盘频繁发送单一字符问题。
This blog aims to record the problem that the keyboard sends a single char while installing Ubuntu OS.
系统版本 system information :20.04.1-Ubuntu SMP Thu Nov 16 14:22:28 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
硬件 hardware :魔霸新锐2021 ROG-Strix-G513QM
安装过程参考
The installation procress reference at
问题描述 Issue description
- 直观现象:笔者在安装Ubuntu20.04.6时,发觉终端无法向上翻找历史记录,始终被拉回最后一行。
instantly problem: I found that I cannot scroll up to view history content at terminal. - 切换至tty3以后,或关机以后,在终端上出现
^@
字符。
If I switch to tty3 or before shutdown, it shows that I’m writing^@
char.
图1. 终端出现字符
Other issue:
原因分析:
推测可能性:笔记本自带键盘电路故障。
Probably reason : The keyboard had some circuit problem.
解决方案:
前置知识
- 键盘布局、扫描码 scancode、键码 keycode:Linux通用键位修改(上)-理论基础
- xev命令: Keyboard input
- 键码映射、udev:Map scancodes to keycodes
- 编写自定义的scancode->keycode规则: Linux通用键位修改(中)-实际操作
解决步骤
使用命令xev
查看键盘事件,发现serial 37
会一直按下。
使用evtest
查找输入设备,如下
event7即Asus Keyboard,终端输入7,回车,即可看到对应的scancode ff310038 被按下,且频繁发送Event code 148 (自定义编程键盘)。这里可以看出是rog键损坏了造成的。
因此,一个暂时的解决方法就是将这个键映射到保留区上,这样系统就不会对键盘作出响应。操作如下(各指令具体含义均在前置知识可找到):
nano /etc/udev/hwdb.d/99-personal-kdb.hwdb
nano
可以换成任何文本编辑器,添加一条映射关系,然后重启即可:
evdev:input:b0003*
KEYBOARD_KEY_ff310038=reserved