當前位置: 首頁>>技術教程>>正文


udev – 如何更改單個設備(羅技演示者)的鍵盤映射?

,

問題描述

我的 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 重新映射到 BNextN 等等。

如何僅更改此設備的鍵映射(因為我當然不想全局重新映射這些鍵代碼)?

最佳辦法

我從未這樣做過,但我認為您需要在 /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

    1. 打開文件:gksudo gedit /lib/udev/rules.d/95-keymap.rules

    2. 在文件的底部,但在 LABEL="keyboard_end" 行之前,添加:

      \\n

      ENV{ID_VENDOR}=="Logitech*", ATTRS{idProduct}=="c52d", RUN+="keymap $name logitech-r400"\\n
    3. 保存,關閉,重啟後按鈕應該會改變亮度。

次佳辦法

我在 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

參考資料

本文由Ubuntu問答整理, 博文地址: https://ubuntuqa.com/zh-tw/article/13149.html,未經允許,請勿轉載。