linux 键位映射到不同的键

快捷键 bind

可以简单使用bind来操作快捷键

bind -p         					#功能键系统
bind -l								#函数库功能,显示按键组合功能
bind -p vim							#列出对应功能的快捷键
bind -x  keyse:shell_command 		#绑定命令
bind -x '"\C-\M-v":vim'				#ctrl+alt+v 调用vim
#keyseq可以使用showkey -a命令来获取
[tom@tom-virtual-machine ~]$showkey -a

Press any keys - Ctrl-D will terminate this program

^M       13 0015 0x0d 字母M
^C        3 0003 0x03 Ctrl-C
^D        4 0004 0x04 Ctrl-D 退出

字符终端

  1. showkey 等待按下某个键,如果未在 10 秒内按下任何键,则退出。这里用来看按下对应键位的keycode值,用来在后面进行更改。
    在这里插入图片描述

  2. dumpkeys命令用来将键盘的对映表写到标准输出之中,输出的格式可以被 loadkeys 命令载入

[root@ton home]#dumpkeys -l 		#打印长信息
...
Recognized modifier names and their column numbers:
shift             1
altgr             2
control           4
alt               8
shiftl           16
shiftr           32
ctrll            64
ctrlr           128
capsshift               256
[root@ton home]#dumpkeys -f    #完整格式配列输出

在这里插入图片描述
keymaps 0-2,4-6,8-9,12中,代表配置的是键值配列表的第0列、第1列等9列,第0列plain为字面键值,第一列为与shift组键值,如上dumpkeys -l输出所示为,第2列为右alt,第8列为左alt等等。

[root@ton home]#dumpkeys -1 > tt.dmp        #单行显示键盘映射 
或者 
[root@ton home]#dumpkeys -S 2 > simple.dmp   #单行格式,方便编辑

在这里插入图片描述

[root@ton home]#dumpkeys -S 3 > simple.dmp    #输出精简配列格式

在这里插入图片描述

[root@ton home]#dumpkeys --compose-only							#配置组合键
compose '`' 'A' to '?'
compose '`' 'a' to '?'
compose '\'' 'A' to '?'
[root@ton home]#dumpkeys --keys-only | head 				#只显示键值配置信息
keymaps 0-2,4-6,8-9,12
keycode   1 = Escape          
        shift   keycode   1 = F30             
        alt     keycode   1 = Meta_Escape     
        shift   alt     keycode   1 = Meta_Escape     
        control alt     keycode   1 = Meta_Escape     
keycode   2 = two              exclam          
        alt     keycode   2 = Meta_one    
[root@ton home]#dumpkeys --funcs-only    #显示功能键信息
string F1 = "\033[[A"
string F2 = "\033[[B"
string F3 = "\033[[C"
string F4 = "\033[[D"
....
string Next = "\033[6~"
string Macro = "\033[M"
string Pause = "\033[P"
string F30 = "sudo loadkeys /home/test.dmp 2>&1 >/dev/null \012"
  1. loadkeys 加载个人配置的键盘映射。
[root@ton home]#dumpkeys -f > test.dmp
[root@ton home]#vim test.dmp 
[root@ton home]#loadkeys test.dmp 
Loading test.dmp

更改默认配置

[root@ton ~]#loadkeys us
Loading /lib/kbd/keymaps/i386/qwerty/us.map.gz

[root@ton ~]#cd /lib/kbd/keymaps/i386/qwerty/
[root@ton qwerty]#cp us.map.gz my.map.gz
[root@ton qwerty]#gunzip my.map.gz 
[root@ton qwerty]#gzip my.map 

[root@ton ~]#loadkeys my
Loading /lib/kbd/keymaps/i386/qwerty/my.map.gz

tips

#利用keymap的字符串绑定功能,绑定命令,进行命令的输出。
keymaps 0-2,4-6,8-9,12                                                                                                      
keycode   1 = Escape           F30       Escape           Escape           Escape           Escape     Meta_Escape      Meta_Escape      Meta_Escape
string F30 = "cd /home/tom/ \n"     #将F30绑定到cd命令上,此处需在命令尾加\n

在这里插入图片描述
在终端下,esc+shift则自动运行cd /home/tom命令,将string F30改成string F30 = "sudo loadkeys /home/test.dmp 2>&1 >/dev/null \n""如下,可以使用esc+shift进行不用的键盘配列切换。
在这里插入图片描述
准备俩键盘配列来回切换
在这里插入图片描述

X11 windos下

xev | awk -F'[ )]+' '/^KeyPress/ { a[NR+2] } NR in a { printf "%-3s %s\n", $5, $8 }'

在这里插入图片描述

xmodmap

#将q与w对调
xmodmap -e "keycode 25 = q"
xmodmap -e "keycode 24 = w"
KeyRelease event, serial 31, synthetic NO, window 0x800001,
    root 0x5a, subw 0x800002, time 4435296, (28,32), root:(228,193),
    state 0x10, keycode 24 (keysym 0x71, q), same_screen YES,
    XLookupString gives 1 bytes: (71) "q"
    XFilterEvent returns: False

KeyPress event, serial 31, synthetic NO, window 0x800001,
    root 0x5a, subw 0x800002, time 4437437, (28,32), root:(228,193),
    state 0x10, keycode 25 (keysym 0x77, w), same_screen YES,
    XLookupString gives 1 bytes: (77) "w"
    XmbLookupString gives 1 bytes: (77) "w"
    XFilterEvent returns: False
KeyRelease event, serial 31, synthetic NO, window 0x800001,
    root 0x5a, subw 0x800002, time 4721031, (62,43), root:(314,256),
    state 0x10, keycode 25 (keysym 0x77, w), same_screen YES,
    XKeysymToKeycode returns keycode: 24
    XLookupString gives 1 bytes: (77) "w"
    XFilterEvent returns: False
xmodmap -pke > ~/.Xmodmap				#保存当前键盘配列

参考http://t.zoukankan.com/yinheyi-p-10146900.html

tips

setleds						#命令一设定键盘上方三个LED的状态
调整打字延迟和速率
例将打字延迟设置为 200 毫秒,将打字速率设置为 30Hz
[root@ton ~]#kbdrate -d 200 -r 30
Typematic Rate set to 30.0 cps (delay = 250 ms)

参考https://wiki.archlinux.org/title/Linux_console/Keyboard_configuration

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值