在 GNU/Linux 下使用键盘功能键

{撰文/Vern Sun}

几年前买的 Razer Lycosa 键盘,左上角有 6 个功能键,外加 1 个键盘背景灯开关键。

Razer

一直以来我都认为这 6 个功能键在 GNU/Linux 下没有驱动是无法使用的。不过今天碰巧看到一篇帖子,我从中发现了 xev 这个工具。启动 xev,点击这些个功能键,很幸运,键码都能被捕获,它们的 keycode 分别是:

162, 164, LO 174, 176
144, 153, GO sw

接着我写了这样的 ~/.xmodmaprc:

keycode 162 = F13
keycode 164 = F14
keycode 144 = F15
keycode 153 = F16
keycode 174 = F17
keycode 176 = F18

然后我又在 Awesome 的配置文件 ~/.config/awesome/rc.lua 添加了这些键绑定:

table.insert(globalkeys, key({ }, "F13", function () awful.util.spawn("mocp -G") end))
table.insert(globalkeys, key({ }, "F14", function () awful.util.spawn("mocp -x") end))
table.insert(globalkeys, key({ }, "F15", function () awful.util.spawn("mocp -r") end))
table.insert(globalkeys, key({ }, "F16", function () awful.util.spawn("mocp -f") end))
table.insert(globalkeys, key({ }, "F17", function () awful.util.spawn("mocp -v -5") end))
table.insert(globalkeys, key({ }, "F18", function () awful.util.spawn("mocp -v +5") end))

相信有了 xev 和 xmodmap,其他多媒体键盘上的功能键也可以很容易的在 GNU/Linux 系统下正常使用了。

{ source }

Read More:

30 Comments

  1. 1 oceanboo Commented @ 2009-04-27 9:37Reply to this comment

    toy该打了,呵呵。

  2. 2 YCF.name Commented @ 2009-04-27 9:38Reply to this comment

    这类文章要顶! 我的笔记本的功能键就用xmodmap整的

  3. 3 bingyuan Commented @ 2009-04-27 9:45Reply to this comment

    原来Toy还买过这样的外设,很爱玩游戏?

  4. 4 hmy Commented @ 2009-04-27 9:54Reply to this comment

    以下是我的keymap修改。把笔记本上的windows键当成ctrl键来用

    remove mod4 = Super_L
    add Control = Super_L
    
  5. 5 eric Commented @ 2009-04-27 10:00Reply to this comment

    这么说来,我家的那个无线键盘未必不能用滚轮和功能键了。

  6. 6 tchaikov Commented @ 2009-04-27 10:08Reply to this comment

    也可以不用 xmodmap 的,直接用类似 "#162" 的名字就能表示一个键了。

  7. 7 ivenvd Commented @ 2009-04-27 10:11Reply to this comment

    呵呵,用这个可不可以把笔记本的快捷键搞定呢?

  8. 8 hmy Commented @ 2009-04-27 10:20Reply to this comment

    @ivenvd 可以的

  9. 9 adaml Commented @ 2009-04-27 11:06Reply to this comment

    @tchaikov:

    求详解,我的openbox貌似不行

  10. 10 YCF.name Commented @ 2009-04-27 11:18Reply to this comment

    @ivenvd 我的笔记本就是这样弄的! @adaml 在~/.xinitrc加入xmodmap ~/.Xmodmap & 我ide.Xmodmap内容:

    keycode 160 = XF86AudioMute
    keycode 176 = XF86AudioRaiseVolume
    keycode 174 = XF86AudioLowerVolume
    keycode 223 = XF86Sleep
    
  11. 11 YCF.name Commented @ 2009-04-27 11:20Reply to this comment

    @ivenvd 我的笔记本就是这样弄的!

    @adaml 在~/.xinitrc加入xmodmap ~/.Xmodmap &

    我.Xmodmap内容:

    keycode 160 = XF86AudioMute

    keycode 176 = XF86AudioRaiseVolume

    keycode 174 = XF86AudioLowerVolume

    keycode 223 = XF86Sleep

    怎么不换行...

  12. 12 Toy Commented @ 2009-04-27 11:27Reply to this comment

    @YCF.name: 贴代码只需保持有缩进,分行需在中间保留空行。

  13. 13 adaml Commented @ 2009-04-27 11:33Reply to this comment

    @YCF.name:

    我也是这么写的,只不过tchaikov说不用定义嘛

  14. 14 zer4tul Commented @ 2009-04-27 11:38Reply to this comment

    Fn难度,其他没问题

  15. 15 iveney Commented @ 2009-04-27 12:49Reply to this comment

    在用keytouch

  16. 16 YCF.name Commented @ 2009-04-27 13:54Reply to this comment

    keycode 160 = XF86AudioMute

    keycode 176 = XF86AudioRaiseVolume

    keycode 174 = XF86AudioLowerVolume

    keycode 223 = XF86Sleep

    Test!

  17. 17 YCF.name Commented @ 2009-04-27 13:55Reply to this comment

    @ Toy 怎么缩进...

    sss
    
  18. 18 YCF.name Commented @ 2009-04-27 14:00Reply to this comment

    我看了下页面的代码,换行保留空行是很对的.

    因为如果回车就换行的话,就是要加入换行元素

    而 br 元素很不好!还是用段落p换行好些!

  19. 19 yogoloth Commented @ 2009-04-27 14:00Reply to this comment

    本文的写法是awesome专用的,YCF的写法,也是必须用startx启动,才会有用。gdm的话要编辑.xsession。 话说我的笔记本没有win键,awsome用得很郁闷,也是用这个方法绑到功能键上去的。这玩艺儿很厉害。

  20. 20 tchaikov Commented @ 2009-04-27 15:04Reply to this comment

    @adaml 对不起,就像 yogoloth 说的。这种写法只是用在 awesome 里面。openbox 就不清楚啦。

  21. 21 YCF.name Commented @ 2009-04-27 17:36Reply to this comment

    @yogoloth

    把xmodmap /root/.Xmodmap &

    写在/etc/rc.local不就都好了。。。(未测试)

    关键就是让这条指定运行了!

  22. 22 黑日白月 Commented @ 2009-04-27 18:15Reply to this comment

    很多笔记本的快捷键在 2.6.29 中被支持了,譬如我的 Asus 的本本在 2.6.29 时就多了一个 asus_keyboard (貌似这么写)的模块,之后无需任何配置在 GNOME 下所有快捷键都可以使用了。

  23. 23 chisiyuan Commented @ 2009-04-27 18:34Reply to this comment

    我的hp笔记本快捷键在hardy的gnome里就已经支持了,有个外接键盘的多媒体键也能用……

  24. 24 Chen Xing Commented @ 2009-04-27 19:23Reply to this comment

    有的笔记本的快捷键是以ACPI消息的形式发送的,比如Thinkpad的Fn+Fx系列,xev抓不到的键可以这样试一下

  25. 25 fan Commented @ 2009-04-27 19:59Reply to this comment

    炫耀贴啊

  26. 26 efan Commented @ 2009-04-27 20:35Reply to this comment

    更希望鼠标的功能键能在linux下使用~~~

  27. 27 nasofe Commented @ 2009-04-27 23:31Reply to this comment

    感觉 keytouch 就可以用了

  28. 28 gcell Commented @ 2009-04-28 0:47Reply to this comment

    xev 和 xmodmap 是启用功能键的利器,但是还是有很多笔记本的功能键和acpi扯到了一起,这两个工具无效……

  29. 29 Cheese Commented @ 2009-04-30 18:17Reply to this comment

    学习了

  30. 30 fire Commented @ 2009-05-30 9:49Reply to this comment

    openbox有没有谁在用? 我这边快捷键运行指令不能有空格是个什么说法