Fluxbox / xbindkeys 多媒体键盘

Fluxbox 使用多媒体键盘

搞了好一阵子才弄明白,我的是微软的键盘Microsoft Multimedia Keyboard用Fluxbox的时候如果不用 特殊的按键很不爽。搞了一阵终于搞定了。
要看一下这个文件:http://gentoo-wiki.com/HOWTO_Use_Multimedia_Keys#Fluxbox

首先安装这个
emerge xev
然后运行 xev

现在随便按一个键可以得到一个结果,比如

KeyPress event, serial 32, synthetic NO, window 0×1400001,
root 0×1a5, subw 0×1400002, time 2923983055, (53,26), root:(109,104),
state 0×0, keycode 161 (keysym 0×0, NoSymbol), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False

keycode后面就是数值。

通过这行命令,然后安顺序按键,可以得到输出结果:

xev | grep keycode |
sed s/”^.*keycode *([0-9]+).*$”/”keycode 1 = “/ |  uniq

也可以使用这个命令查看单个按键数值:

xev | sed -n ‘/keycode/!d;s/^.*keycode *([0-9]+).*$/keycode 1 = /;p’

数值如这样 就没有问题: keycode 164 =

然后创建一个文件
vi .Xmodmap

! This works with Trust Silverline Direct Access keyboard
! Use ! for comments

keycode 222 = XF86PowerOff
keycode 223 = XF86Sleep
keycode 236 = XF86Mail
keycode 229 = XF86Search
keycode 230 = XF86Favorites
keycode 178 = XF86WWW

keycode 162 = XF86AudioPlay
keycode 164 = XF86AudioStop
keycode 160 = XF86AudioMute
keycode 144 = XF86AudioPrev
keycode 153 = XF86AudioNext
keycode 176 = XF86AudioRaiseVolume
keycode 174 = XF86AudioLowerVolume

keycode要对应你的 按键数值,上面的这个正好符合我的按键,应该是标准按键数值。

在英文的教程中,说要在.xsession里面添�
/usr/bin/xmodmap $HOME/.Xmodmap
但是我添加了以后没有任何效果。所以我抛弃了这步,
我的操作如下:

vi .fluxbox/keys
添加:

None XF86AudioPlay :ExecCommand /usr/bin/audacious –play
None XF86AudioStop :ExecCommand /usr/bin/audacious –stop
None XF86AudioPrev :ExecCommand /usr/bin/audacious –rew
None XF86AudioNext :ExecCommand /usr/bin/audacious –fwd
None XF86AudioLowerVolume :ExecCommand amixer -q set PCM 2- unmute

(因为我使用audacious听音乐,所以注意参数就可以了,参数可以用audacious –help查看如果用xmms之类的可以自己更改)

然后vi .fluxbox/startup
添加: xmodmap .Xmodmap &

就可以了。这样键盘就可以控制音乐了。

还有很多按键如何使用?
如果有些按键没有keycode怎么办。那说明需要用setkeycodes来设定一个keycode给他。这样就可以用了。
做一个例子:

我的键盘有一个Messenger,但是我找不到keycode
先点击Messenger按键

然后打开xterm输入:

tail /var/log/messages
能看到如下结果:

Feb 11 14:27:26 localhost atkbd.c: Unknown key pressed (translated set 2, code 0×96 on isa0060/serio0).
Feb 11 14:27:26 localhost atkbd.c: Use ’setkeycodes e016 ‘ to make it known.
Feb 11 14:27:27 localhost atkbd.c: Unknown key released (translated set 2, code 0×96 on isa0060/serio0).
Feb 11 14:27:27 localhost atkbd.c: Use ’setkeycodes e016 ‘ to make it known.

我们知道可以使用setkeycodes e016 给出一个keycode来
使用命令:
setkeycodec e016 135

参考两个连接:
http://linuxcommand.org/man_pages/setkeycodes8.html
http://cweiske.de/howto-laptop/ch07.html

第一个e016是看到的结果按键数值。后面的135是kernel没有用过的keycode. 这里有解释:


Where the first number (e008) is what you see in dmesg, and the second
number (136) is an unused keycode in your kernel. In general you can
find a good keycode by taking the last 2 digits of this first number,
converting it from hex (base-16) to decimal (base-10) and adding 128.


This will set up the proper scancode – keycode mapping every boot. To
set them up without rebooting, run the following as root:

sh /etc/conf.d/local.start


After you have the proper mappings setup, restart X and try running xev
again, to ensure that a keycode is displayed for each multimedia key
you want to use.

然后在使用xev找到keycode.比如给出的keycode是210
那么添�
vi .Xmodmap
keycode 210 = XF86Messenger

在添�
vi .fluxbox/keys
None XF86Messenger :ExecCommand /usr/bin/gaim

然后运行一个xmodmap .Xmodmap就可以了。
这样Messenger按键直接打开gaim.

这是我的fluxbox/keys

None XF86WWW :ExecCommand /usr/bin/firefox
None XF86Mail :ExecCommand /usr/bin/evolution
None XF86Messenger :ExecCommand /usr/bin/gaim
None XF86Pictures :ExecCommand /usr/bin/thunar /home/muvsn/My Pictures/

这是.Xmodmap

keycode 236 = XF86Mail
keycode 229 = XF86Search
keycode 230 = XF86Favorites
keycode 178 = XF86WWW
keycode 162 = XF86AudioPlay
keycode 164 = XF86AudioStop
keycode 160 = XF86AudioMute
keycode 144 = XF86AudioPrev
keycode 153 = XF86AudioNext
keycode 176 = XF86AudioRaiseVolume
keycode 174 = XF86AudioLowerVolume
keycode 210 = XF86Messenger
keycode 158 = XF86Pictures

————————————————————————–
emerge xbindkeys

A list of possible keysyms can be found in
/usr/share/X11/XKeysymDB (on Gentoo),
/usr/lib/X11/XKeysymDB or /usr/share/X11/XKeysymDB
(the location of XKeysymDB may differ across distributions). The
following is a list of the more commonly used keysyms as found in
XKeysymDB.

把xbindkeys 放入启动项

vi .xbindkeysrc

“/usr/bin/thunar /home/olo/music/Music/”
XF86Music
“/usr/bin/thunar”
XF86MyComputer
“/usr/bin/pidgin”
XF86Messenger
“/usr/bin/audacious”
XF86CD
“/usr/bin/thunar /home/olo/Pictures/”
XF86Pictures
“/usr/bin/gcalctool”
XF86Calculator
“/usr/bin/firefox”
XF86WWW
“/usr/bin/audacious –stop”
Control+Alt+End
“/usr/bin/audacious –play”
Control+Alt+Home
“/usr/bin/audacious –fwd”
Control+Alt+Next
“/usr/bin/audacious –rew”
Control+Alt+Prior

/etc/conf.d/local.start (gentoo)
/etc/rc.local (fedora)

setkeycodes e03c 91
setkeycodes e005 90
setkeycodes e064 89

在Gnome里自动启动xbindkeys

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s