问题描述
我的 Logitech R400 Presenter 发送以下密钥代码:
keycode 112 (keysym 0xff55, Prior) [page up]
keycode 117 (keysym 0xff56, Next) [page down]
keycode 60 (keysym 0x2e, period)
keycode 71 (keysym 0xffc2, F5)
keycode 9 (keysym 0xff1b, Escape)
基本上,我想用这个演示器来远程控制 Banshee,所以我想将 Prior
重新映射到 B
, Next
到 N
等等。
如何仅更改此设备的键映射(因为我当然不想全局重新映射这些键代码)?
最佳办法
我从未这样做过,但我认为您需要在 /lib/udev/keymaps/
中创建一个键盘映射文件并将您的设备的规则添加到 /lib/udev/rules.d/95-keymap.rules
细节:
-
udev 键映射将扫描代码映射到键代码,因此您需要找到两者来创建键映射文件。要查找扫描代码,请运行以下命令并按下设备上的按钮:
\n
sudo /lib/udev/keymap -i input/event5\n
\n
您可能需要为 event* 尝试不同的数字。输出应如下所示:
\n
scan code: 0x70037 key code: dot\nscan code: 0x70029 key code: esc\nscan code: 0x7003E key code: f5\nscan code: 0x7004B key code: pageup\nscan code: 0x7004E key code: pagedown\n
\n
可以找到关键代码列表 here 。
\n
现在创建键盘映射文件(我将其存储为 /lib/udev/keymaps/logitech-r400):
\n
0x70037 brightnessdown\n0x70029 brightnessup\n0x7003E brightnessdown\n0x7004B brightnessup\n0x7004E brightnessdown\n
\n
没有做任何有用的事情 – 只是一个测试以轻松查看它是否有效。
-
要临时测试新的键盘映射,请运行:
\n
sudo /lib/udev/keymap input/event5 /lib/udev/keymaps/logitech-r400\n
\n
这应该导致这样的输出:
\n
Remapped scancode 0x70037 to 0xe0 (prior: 0x34)\nRemapped scancode 0x70029 to 0xe1 (prior: 0x01)\nRemapped scancode 0x7003e to 0xe0 (prior: 0x3f)\nRemapped scancode 0x7004b to 0xe1 (prior: 0x68)\nRemapped scancode 0x7004e to 0xe0 (prior: 0x6d)\n
\n
按钮现在应该改变亮度。
-
如果要使该更改永久生效,则需要向
/lib/udev/rules.d/95-keymap.rules
添加一条 udev 规则,以将键盘映射文件应用于设备。\n-
打开文件:
gksudo gedit /lib/udev/rules.d/95-keymap.rules
-
在文件的底部,但在
LABEL="keyboard_end"
行之前,添加:\\n
ENV{ID_VENDOR}=="Logitech*", ATTRS{idProduct}=="c52d", RUN+="keymap $name logitech-r400"\\n
-
保存,关闭,重启后按钮应该会改变亮度。
-
次佳办法
我在 Ubuntu 16.04 上。我做了一个指南 here
\\n
Detecting with evtest
\\n
sudo evtest\\n
\\n
Look at the device list :
\\n
/dev/input/event0: Lid Switch\\n/dev/input/event1: Power Button\\n/dev/input/event2: Sleep Button\\n/dev/input/event3: Power Button\\n/dev/input/event4: AT Translated Set 2 keyboard\\n/dev/input/event5: Video Bus\\n/dev/input/event6: USB Optical Mouse\\n/dev/input/event7: AlpsPS/2 ALPS DualPoint Stick\\n/dev/input/event8: AlpsPS/2 ALPS DualPoint TouchPad\\n/dev/input/event9: Logitech USB Receiver\\n/dev/input/event10: Logitech USB Receiver\\n/dev/input/event11: HDA Intel PCH Dock Mic\\n/dev/input/event12: HDA Intel PCH Headset Mic\\n/dev/input/event13: HDA Intel PCH Dock Line Out\\n/dev/input/event14: HDA Intel PCH Headphone\\n/dev/input/event15: HDA Intel PCH HDMI/DP,pcm=3\\n/dev/input/event16: HDA Intel PCH HDMI/DP,pcm=7\\n/dev/input/event17: HDA Intel PCH HDMI/DP,pcm=8\\n/dev/input/event18: Integrated Webcam\\n/dev/input/event19: Dell WMI hotkeys\\nSelect the device event number [0-19]: 9\\nInput driver version is 1.0.1\\nInput device ID: bus 0x3 vendor 0x46d product 0xc52d version 0x111\\nInput device name: "Logitech USB Receiver"\\n
\\n
Took the first “Logitech USB Receiver”, here it has event id 9.
\\n
Testing ... (interrupt to exit)\\n
\\n
OK now evtest wants inputs, just click on the Logitech remote buttons,\\n I got this (simplified):
\\n
[>] value 7003e (KEY_PRESENTATION)\\n[>] value 70029 (KEY_PRESENTATION)\\n[ ] value 70037 (KEY_DISPLAYTOGGLE)\\n < value 7004b (KEY_PAGEUP)\\n > value 7004e (KEY_PAGEDOWN)\\n
\\n
Note: I discovered after that clicking multiple times on [>] was giving 7003e, then 70029, then 7003e, etc. I don’t know why.
\\n
Modifying udev conf
\\n
Now that we have input codes, let’s have a look at udev conf:
\\n
sudo gedit /lib/udev/hwdb.d/60-keyboard.hwdb\\n
\\n
Search for “R400” and replace presentation & displaytoggle by what you\\n want, playpause & stopcd arrow keys:
\\n
# Logitech Presenter R400\\nevdev:input:b0003v046DpC52D*\\n KEYBOARD_KEY_070029=playpause # bottom left [>] was "presentation" \\n KEYBOARD_KEY_07003e=playpause # bottom left [>] was "presentation" \\n KEYBOARD_KEY_070037=stopcd # bottom right [ ] was "displaytoggle"\\n
\\n
As previously noted, because 07003e & 070029 are the same button, I\\n gave them the same output up key. The 7004b & 7004e does not appear\\n here by default, maybe because they are native PAGEUP & PAGEDOWN\\n inputs and not related to “Logitech Presenter R400”. Let’s add them:
\\n
KEYBOARD_KEY_07004b=previoussong # top left <\\n KEYBOARD_KEY_07004e=nextsong # top right > \\n
\\n
Here is my final conf:
\\n
KEYBOARD_KEY_07004b=previoussong # top left <\\n KEYBOARD_KEY_07004e=nextsong # top right >\\n KEYBOARD_KEY_070029=playpause # bottom left [>] was "presentation"\\n KEYBOARD_KEY_07003e=playpause # bottom left [>] was "presentation"\\n KEYBOARD_KEY_070037=stopcd # bottom right [ ] was "displaytoggle"\\n
\\n
Reloading (new) rules
\\n
sudo udevadm hwdb --update\\n
\\n
Then by using the same event id we chose before, here event id 9:
\\n
sudo udevadm trigger /dev/input/event9\\n
\\n
You can check this new mapping in a web browser, for example:
\\n
$('body').on('keydown', function(e){ console.log(e.key) })\\n
\\n
That gave me:
\\n
[>] ArrowUp\\n[ ] ArrowDown\\n < ArrowLeft\\n > ArrowRight\\n
\\n