User Tools

Site Tools


doc:appunti:linux:sa:remap_keyboard_keys

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
doc:appunti:linux:sa:remap_keyboard_keys [2021/12/07 10:54] – [Customize events using udev] niccolodoc:appunti:linux:sa:remap_keyboard_keys [2021/12/07 11:50] (current) – [xmodmap] niccolo
Line 17: Line 17:
 </code> </code>
  
-It is possibile to customize the ACPI events to reassign the brightness keys to plain function keys, but it is not the preferred way (see [[#acpi_and_evemu|ACPI and evemu]]), because it requires to run an additional sofware layer (the acpid daemon) and the execution of slow action scripts.+It is possibile to customize the ACPI events to reassign the brightness keys to plain function keys, but it is not the preferred way (see [[#acpi_and_evemu|ACPI and evemu]]), because it requires to run an additional sofware layer (the acpid daemon) and the execution of slow action scripts. The simplest method is to **[[#customize_events_using_udev_and_hwdb|customize input events using udev and hwdb]]**.
  
 It seems that the LCD (DISPLAYTOGGLE) multimedia function is intercepted by the hardware and it is not handled as an input event nor as an ACPI event by the operating system. It seems that the LCD (DISPLAYTOGGLE) multimedia function is intercepted by the hardware and it is not handled as an input event nor as an ACPI event by the operating system.
Line 181: Line 181:
 ===== Configuration example for the Teclast F6 notebook ===== ===== Configuration example for the Teclast F6 notebook =====
  
-The following is the file **/etc/udev/hwdb.d/90-custom-keyboard.hwdb** which I use on my Teclast F6 notebook:+The following is the file **/etc/udev/hwdb.d/90-teclast-f6-keyboard.hwdb** which I use on my Teclast F6 notebook:
  
 <file> <file>
-# /etc/udev/hwdb.d/90-custom-keyboard.hwdb +# /etc/udev/hwdb.d/90-teclast-f6-keyboard.hwdb 
-#+
 # Keyboard remapping for the Teclast F6 notebook. # Keyboard remapping for the Teclast F6 notebook.
-# 2021-05-13 Niccolo Rigacci <niccolo@rigacci.org>+# 2021-12-07 Niccolo Rigacci <niccolo@rigacci.org>
 # #
 # The following udev hwdb configuration swaps the Fn behaviour # The following udev hwdb configuration swaps the Fn behaviour
-# on keys F2, F3, F4, F8, F9, F10, F11 and F12.+# on keys F2, F3, F4, F6, F7, F8, F9, F10, F11 and F12.
 # It also binds the Fn+ESC to Ctrl+LeftWinLogo+Esc, which can # It also binds the Fn+ESC to Ctrl+LeftWinLogo+Esc, which can
 # be used as keyboard shortcut into XFCE or other desktop # be used as keyboard shortcut into XFCE or other desktop
 # environments to execute a script and toggle the touchpad. # environments to execute a script and toggle the touchpad.
 # #
-# Function keys F1, F6 and F7 cannot be remapped using +# Function key F1 cannot be remapped using udev Hardware 
-udev Hardware Database (as far as I know).+Database (as far as I know).
 # #
-# To make this file effective execute:+# To make this file effective execute (please check the 
 +# input number using lsinput):
 #   systemd-hwdb update #   systemd-hwdb update
 #   udevadm trigger --verbose /dev/input/event0 #   udevadm trigger --verbose /dev/input/event0
 +#   udevadm trigger --verbose /dev/input/event7
 # #
-# To view current binding:+# To view current bindings:
 #   udevadm info /dev/input/event0 #   udevadm info /dev/input/event0
 # #
Line 217: Line 219:
 #   KEYBOARD_KEY_76 => code 85  KEY_ZENKAKUHANKAKU #   KEYBOARD_KEY_76 => code 85  KEY_ZENKAKUHANKAKU
 # #
-Function keys F1, F6 and F7 do not generate events +Fn+F6 and Fn+F7 produce keys 64 and 65 (0x40 and 0x41).
-(verified with evtest and showkey), so they cannot +
-# be remapped. +
-+
-# The following EV_KEY do not work: +
-#   KEY_DISPLAYTOGGLE +
-#   KEY_BRIGHTNESSDOWN +
-#   KEY_BRIGHTNESSUP+
 # #
 +# Function keys F1 does not generate events (verified with
 +# evtest and showkey), so it cannot be remapped.
 +
 +# Teclast AT Keyboard input device.
 evdev:atkbd:dmi:bvnTECLAST:bvr*:bd*:svnTECLAST:pnF6:pvr* evdev:atkbd:dmi:bvnTECLAST:bvr*:bd*:svnTECLAST:pnF6:pvr*
  KEYBOARD_KEY_a0=f2  KEYBOARD_KEY_a0=f2
Line 238: Line 237:
  KEYBOARD_KEY_3d=volumedown  KEYBOARD_KEY_3d=volumedown
  KEYBOARD_KEY_3e=volumeup  KEYBOARD_KEY_3e=volumeup
 + KEYBOARD_KEY_40=brightnessdown
 + KEYBOARD_KEY_41=brightnessup
  KEYBOARD_KEY_42=previoussong  KEYBOARD_KEY_42=previoussong
  KEYBOARD_KEY_43=nextsong  KEYBOARD_KEY_43=nextsong
Line 244: Line 245:
  KEYBOARD_KEY_58=sysrq  KEYBOARD_KEY_58=sysrq
  KEYBOARD_KEY_76=esc  KEYBOARD_KEY_76=esc
 +
 +# F6 and F7 are connected to input "Intel HID events", not keyboard.
 +evdev:name:Intel HID events:dmi:bvnTECLAST:bvr*:bd*:svnTECLAST:pnF6:pvr*
 + KEYBOARD_KEY_14=f6
 + KEYBOARD_KEY_13=f7
 </file> </file>
  
Line 287: Line 293:
 </code> </code>
  
-These keysyms do not produce the expected action; i.e. they don't do anything, despite I associate them to a key and depite that ''evtest'' and ''xev''do report the expected action:+These keysyms do not produce the expected action; i.e. they don't do anything, despite I associate them to a key and despite that ''evtest'' and ''xev''do report the expected action:
  
   * XF86TouchpadToggle, XF86TouchpadOn, XF86TouchpadOff   * XF86TouchpadToggle, XF86TouchpadOn, XF86TouchpadOff
Line 293: Line 299:
  
 ===== ACPI and evemu ===== ===== ACPI and evemu =====
 +
 +**WARNING**: This method is deprecated: it cannot actually swap F6/F7 with Fn+F6/Fn+F7. Used alone it can rempap BrightnessDown and BrightnessUp with F6 and F7, but it cannot remap the vice-versa. It also requires the //acpid// service and it requires the execution of slow scripts on each keypress.
  
 With this recipe we simulate a **keyboard event** (e.g. a function key press/release) when an **ACPI event** occurs (eg. when the **BrightnessDown** or **BrightnessUp** buttons are pressed). With this recipe we simulate a **keyboard event** (e.g. a function key press/release) when an **ACPI event** occurs (eg. when the **BrightnessDown** or **BrightnessUp** buttons are pressed).
Line 330: Line 338:
 WARNING: The **sleep** command was determined empirically, may be it is required to let the default ACPI routine to complete. WARNING: The **sleep** command was determined empirically, may be it is required to let the default ACPI routine to complete.
  
-Once the acpid service is restarted, every time you press the **BrightnessDown** and **BrightnessUp** keys, you get the brightness adjusted and also the key **F6** or **F7** simulated events.+Once the acpid service is restarted, every time you press the **BrightnessDown** and **BrightnessUp** keys, you get the key **F6** or **F7** simulated events **along with the default brightness adjust**.
  
-Now you have to disable the default brightness control behaviour.+To disable (or remap) the default brightness control behaviour we need to customize the input subsystem, disabilng or remapping the **Intel HID events** device. In this case customizing ACPI becomes pointless: you can obtain all the required mapping using only udev and hwdb (see above), leaving ACPI alone.
  
-If the brightness keys are sent as **keyboard keycodes**, simply remap the relevant keycodes to the empty string. The keycodes can be discovered with: +On different hardware, if the multimedia key generates a plain **keyboard keycode**, you can use ''xmodmap'' to remap it, but the mapping only works under the Xserver environment.
- +
-<code> +
-xmodmap -display :0.0 -pke | grep -i monbright +
-keycode 232 = XF86MonBrightnessDown NoSymbol XF86MonBrightnessDown NoSymbol XF86MonBrightnessDown +
-keycode 233 = XF86MonBrightnessUp NoSymbol XF86MonBrightnessUp NoSymbol XF86MonBrightnessUp +
-</code> +
- +
-So we can disable keycodes 232 and 233: +
- +
-<code> +
-xmodmap -e 'keycode 232 =' +
-xmodmap -e 'keycode 233 =' +
-</code> +
- +
-Unfortunately this is not the case with the Teclast F6; the BrightnessDown and BrightnessUp events are not reported as keyboard keycodes. They are instead input events generated by the **Intel HID events** device. Use **lsinput** and **input-events** +
- +
-<code> +
-lsinput +
-... +
-/dev/input/event7 +
-   bustype : BUS_HOST +
-   vendor  : 0x0 +
-   product : 0x0 +
-   version : 0 +
-   name    : "Intel HID events" +
-   bits ev : (null) (null) (null) +
-</code> +
- +
-<code> +
-input-events -t 10 7 +
-18:45:12.250030: (null) ??? 20 +
-18:45:12.250030: (null) ??? (0xe0) pressed +
-18:45:12.250030: (null) code=0 value=0 +
-18:45:12.250066: (null) ??? (0xe0) released +
-18:45:12.250066: (null) code=0 value=0 +
-18:45:12.833473: (null) ??? 19 +
-18:45:12.833473: (null) ??? (0xe1) pressed +
-18:45:12.833473: (null) code=0 value=0 +
-18:45:12.833506: (null) ??? (0xe1) released +
-18:45:12.833506: (null) code=0 value=0 +
-</code> +
- +
-It is possible to disable the input events (but still receive the ACPI events). Discover the id: +
- +
-<code> +
-xinput +
-... +
-    ↳ Intel HID events                          id=12   [slave  keyboard (3)] +
-</code> +
- +
-and disable it: +
- +
-<code> +
-xinput disable 12 +
-</code>+
  
 ===== Web References ===== ===== Web References =====
doc/appunti/linux/sa/remap_keyboard_keys.1638870847.txt.gz · Last modified: 2021/12/07 10:54 by niccolo