键码错乱之解决方法

一、图形界面
解决思路:
1>xev获取keycode
2>xmodmap -pke |grep keycode
3>修改正确的键码并加载

1.运行xev命令
在终端查看键值,如shift+\:
1>正确的键值信息
KeyPress event, serial 34, synthetic NO, window 0x2400001,
    root 0xae, subw 0x0, time 19473292, (685,-121), root:(1316,234),
    state 0x1, keycode 51 (keysym 0x7c, bar), same_screen YES,
    XLookupString gives 1 bytes: (7c) "|"
    XmbLookupString gives 1 bytes: (7c) "|"
    XFilterEvent returns: False

KeyRelease event, serial 34, synthetic NO, window 0x2400001,
    root 0xae, subw 0x0, time 19473356, (685,-121), root:(1316,234),
    state 0x1, keycode 62 (keysym 0xffe2, Shift_R), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyRelease event, serial 34, synthetic NO, window 0x2400001,
    root 0xae, subw 0x0, time 19473388, (685,-121), root:(1316,234),
    state 0x0, keycode 51 (keysym 0x5c, backslash), same_screen YES,
    XLookupString gives 1 bytes: (5c) "\"
    XFilterEvent returns: False

从"keycode 51 (keysym 0x7c, bar)"可以看出"|"键的信息:
keycode: 51
keysym: 0x7c
keyname: bar
char: |
从"keycode 51 (keysym 0x5c, backslash)"可以看出"\"键的信息:
keycode: 51
keysym: 0x5c
keyname: backslash
char: \

2>错误的键值信息
KeyPress event, serial 34, synthetic NO, window 0x1800001,
    root 0x3a, subw 0x0, time 2600336, (127,-103), root:(550,188),
    state 0x1, keycode 51 (keysym 0x7e, asciitilde), same_screen YES,
    XLookupString gives 1 bytes: (7e) "~"
    XmbLookupString gives 1 bytes: (7e) "~"
    XFilterEvent returns: False

KeyRelease event, serial 34, synthetic NO, window 0x1800001,
    root 0x3a, subw 0x0, time 2600400, (127,-103), root:(550,188),
    state 0x1, keycode 62 (keysym 0xffe2, Shift_R), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyRelease event, serial 34, synthetic NO, window 0x1800001,
    root 0x3a, subw 0x0, time 2600448, (127,-103), root:(550,188),
    state 0x0, keycode 51 (keysym 0x23, numbersign), same_screen YES,
    XLookupString gives 1 bytes: (23) "#"
    XFilterEvent returns: False

从"keycode 51 (keysym 0x7e, asciitilde)"可以看出"|"键的信息:
keycode: 51
keysym: 0x7e
keyname: asciitilde
char: ~
从"keycode 51 (keysym 0x23, numbersign)"可以看出"\"键的信息:
keycode: 51
keysym: 0x23
keyname: numbersign
char: #

2.运行xmodmap -pke命令
1>正确的键值信息
keycode  51 = backslash bar backslash bar backslash bar
2>错误的键值信息
keycode  51 = numbersign asciitilde dead_grave dead_tilde

3.
echo "keycode  51 = backslash bar backslash bar backslash bar" > Xmodmap
1>xmodmap Xmodmap [当前系统加载]
2>mv Xmodmap ~/.Xmodmap [登录后自动加载]

二、字符终端
loadkeys -d [加载默认的键盘映射表,默认文件是/usr/share/keymaps/i386/qwerty/defkeymap.kmap.gz]

你可能感兴趣的:(键盘映射,键码)