• BASH > gestion du clavier

      récupérer une saisie

      Si on a une fenêtre 0x2e0000e (xwininfo puis sélection de la fenêtre en question) et qu’on lance xev -id 0x2e0000e > plop.txt dans un terminal, tous les évènements ayant lieu dans la fenêtre 0x2e0000e (souris + clavier) seront enregistrés dans plop.txt. Pour l’utiliser dans un script, il faut traiter le fichier plop.txt en permanence, pour savoir quelle touche est pressée/relâchée.

       

      xbindkeys pour configurer un évènement clavier. Ex: lancer un script qui affiche "Coucou !" toutes les secondes et qui s’arrêtera lorsque la touche "a" sera pressée :

      #!/bin/bash
      pid=$$
      suffix=$(date +%F_%H-%M-%S)_$pid
      filetest=.dtpid_$suffix
      touch $filetest
      mybind=.myxbindrc_$suffix
      echo "\"rm $filetest\"" > $mybind echo "a" >> $mybind
      xbindkeys -f $mybind
      pidbind=`pidof xbindkeys`
      while [ -f $filetest ] do echo "Coucou !" sleep 1 done
      kill -9 $pidbind
      rm $mybind

       

      xbindkeys capture les événements, mais ne les restitue pas. Ex, si la touche "a" lance Firefox et que l’on tape du texte dans un xterm, dès l’appui du "a", Firefox sera lancé mais le "a" ne sera pas écrit dans l’xterm. Il faut un keylogger

      xbindkeys

      Permet de lancer des commandes shell depuis le clavier ou la souris grâce à un fichier de conf.

      xbindkeys [-d] [-f file] [-h] [--display|-X display-name] [-v] [-s] [-k] [-mk] [-g geom]

      -V version

      -d Print a default rc file

      -f Use an alternative rc file

      -h help

      -X Set X display to use

      -v verbose !!!

      -s Show the actual keybinding

      -k Identify one key pressed

      -mk Identify multi key pressed

      -g taille et position de la fenêtre ouverte avec -k ou -mk

      -n don’t start as daemon

       

      xbindkeys &

      Démarrer xbindkeys au démarrage de X en écrivant ci-dessus dans $HOME/.xsession

      xbindkeys utilise le fichier de conf $HOME/.xbindkeyrc. Si il n’est pas présent, créer un fichier par défaut :

      xbindkeys --defaults > $HOME/.xbindkeysrc

      Quelques exemples de xbindkeysrc: (default) - (1) - (2)

       

      Utilitaires: script to enable double click on keys or mouse buttons : double_click.sh or doubleclick_delayed.sh .

      Tutorial: How to Use The Buttons of Your Trackball in Linux

       

      remapping de Scroll Lock par Enter:

      sudo sed -i -e '71s|.*|key<SCLK>{[Return]};|' /usr/share/X11/xkb/symbols/pc && sudo dpkg-reconfigure xkb-data

       

      Command for Right Shift key:

      sudo sed -i '29s|.*|key<RTSH>{[Return]};|' /usr/share/X11/xkb/symbols/pc && sudo dpkg-reconfigure xkb-data

       

      Undo remapping reinstall xkb-data package. In terminal:

      sudo apt-get install --reinstall xkb-data

      INPUT-REMAPPER

      sudo apt install input-remapper

       

      key(a) touche A

      key(symbol=Control_L) touche Control gauche

      key(symbol=Super_L) Touche Windows gauche

       

      Changer la touche WINDOWS (SUPER_L) en touche A :

      {
        "mapping": {
          "1,125,1": [
            "a",
            "keyboard"
          ]
        }
      }

      # Usage

      1 - Sélectionner le périphérique (clavier, souris, manette) depuis Device

      2 - Créer un nouveau preset depuis Rename.

      3 - Clic sur new entry > clic sur Change Key > appuyer sur la/les touche(s) que l’on veut mapper.

      4 - Remplir le champs en dessous par la/les touche(s) de remplacement (voir la syntaxe ci-dessous)

      Pour une macro : Dans le même champs, le fait d’écrire une macro (syntaxe), puis en appuyant sur ENTRÉE pour sauter de ligne (passage en mode multi-line).

      5 - Clic sur Apply pour activer (inject) le mappage.

       

      NOTE : la sauvegarde se fait automatiquement !

      NOTE : Ne pas oublier de cliquer sur Stop injection pour modifier à nouveau le mappage.

       

      Pour passer en mode debuggage :

      input-remapper-gtk -d

       

      Shift+1 -> a this will inject a lowercase `a` if the toggle is on and an uppercase `A` if it is off. The exact behaviour if the toggle is off is dependent on keys (are modifiers involved?), the order in which they are pressed and on your environment (X11/Wayland). By default the toggle is on.

       

      Combinations

      Control_L + a

       

      ## UI Shortcuts

      CTRL+R refreshes the device list

       

      Liste complète des combinaisons possibles (nom des touches)

      input-remapper-control --symbol-names

       

      Nom de la touche alphabétique : KEY_A ou a

       

      External tools : input-remapper-xautopresets: https://github.com/DreadPirateLynx/input-remapper-xautopresets

       

      Configuration Files

      Ficher de configuration par défaut : ~/.config/input-remapper/config.json, sans aucun mapping, but rather other parameters that are interesting for injections :

      {
         "autoload": {
            "Logitech USB Keyboard": "preset name"
         },
         "version": "1.6"
      }

       

      preset name renvoi vers ~/.config/input-remapper/presets/device name/preset name.json

      On peut trouver le device name avec:

      sudo input-remapper-control --list-devices

       

      Exemple :

      [
        {
          "input_combination": [
            {"type": 1, "code": 307}
          ],
          "target_uinput": "keyboard",
          "output_symbol": "k(2).k(3)",
          "macro_key_sleep_ms": 100
        },
        {
          "input_combination": [
            {"type": 1, "code": 315, "origin_hash": "07f543a6d19f00769e7300c2b1033b7a"},
            {"type": 3, "code": 1, "analog_threshold": 10}
          ],
          "target_uinput": "keyboard",
          "output_symbol": "1"
        },
        {
          "input_combination": [
            {"type": 3, "code": 1}
          ],
          "target_uinput": "mouse",
          "output_type": 2,
          "output_code": 1,
          "gain": 0.5
        }
      ]

       

      * Premier mapping: the key event with code 307 to a macro and sets the time between injected events of macros to 100 ms. The macro injects its events to the virtual keyboard.

      * Deuxième mapping: combination of a key event with the code 315 and a analog input of the axis 1 (y-Axis).

      * Troisième mapping: the y-Axis of a joystick to the y-Axis on the virtual mouse.

       

      Mapping

      As shown above, the mapping is part of the preset. It consists of the input-combination, which is a list of input-configurations and the mapping parameters.

      {
         "input_combination": [
            <InputConfig 1>,
            <InputConfig 2>
         ]
         <parameter 1>: <value1>,
         <parameter 2>: <value2>
      }

       

      The input-combination is a list of one or more input configurations. To trigger a mapping, all input configurations must trigger.

       

      A input configuration is a dictionary with some or all of the following parameters:

       

      | Parameter        | Default | Type                   | Description                                                         |
      |------------------|---------|------------------------|---------------------------------------------------------------------|
      | type             | -       | int                    | Input Event Type                                                    |
      | code             | -       | int                    | Input Evnet Code                                                    |
      | origin_hash      | None    | hex (string formatted) | A unique identifier for the device which emits the described event. |
      | analog_threshold | None    | int                    | The threshold above which a input axis triggers the mapping.        |

       

      type, code always needed. Use the program `evtest` to find Available types and codes. See also the [evdev documentation](https://www.kernel.org/doc/html/latest/input/event-codes.html#input-event-codes)

      origin_hash an internally computed hash. It is used associate the input with a specific /dev/input/eventXX device. This is useful when a single pyhsical device

      creates multiple /dev/input/eventXX devices wihth similar capabilities. Voir : https://github.com/sezanzeb/input-remapper/issues/435

      analog_threshold Setting to zero or omitting means that the input will be mapped to an axis. There can only be one axis input with a threshold of 0 in a mapping. If the `type` is 1 (EV_KEY) the `analog_threshold` has no effect. The `analog_threshold` is needend when the input is a analog axis which should be treated as a key input. If the event type is `3 (EV_ABS)` (as in: map a joystick axis to a key or macro) the threshold can be between `-100 [%]` and `100 [%]`. The mapping will be triggered once the joystick reaches the position described by the value.

       

      If the event type is `2 (EV_REL)` (as in: map a relative axis (e.g. mouse wheel) to a key or macro) the threshold can be anything. The mapping will be triggered once the speed and direction of the axis is higher than described by the threshold.

       

      #### Mapping Parameters

      | Parameter                | Default | Type            | Description                                                                                                             |
      |--------------------------|---------|-----------------|-------------------------------------------------------------------------------------------------------------------------|
      | input_combination        |         | list            | see [above](#input-combination-and-configuration)                                                                       |
      | target_uinput            |         | string          | The UInput to which the mapped event will be sent                                                                       |
      | output_symbol            |         | string          | The symbol or macro string if applicable                                                                                |
      | output_type              |         | int             | The event type of the mapped event                                                                                      |
      | output_code              |         | int             | The event code of the mapped event                                                                                      |
      | release_combination_keys | true    | bool            | If release events will be sent to the forwarded device as soon as a combination triggers see also #229                  |
      | **Macro settings**       |         |                 |                                                                                                                         |
      | macro_key_sleep_ms       | 0       | positive int    |                                                                                                                         |
      | **Axis settings**        |         |                 |                                                                                                                         |
      | deadzone                 | 0.1     | float ∈ (0, 1)  | The deadzone of the input axis                                                                                          |
      | gain                     | 1.0     | float           | Scale factor when mapping an axis to an axis                                                                            |
      | expo                     | 0       | float ∈ (-1, 1) | Non liniarity factor see also [GeoGebra](https://www.geogebra.org/calculator/mkdqueky)                                  |
      | **EV_REL output**        |         |                 |                                                                                                                         |
      | rel_rate                 | 60      | positive int    | The frequency `[Hz]` at which `EV_REL` events get generated (also effects mouse macro)                                  |
      | **EV_REL as input**      |         |                 |                                                                                                                         |
      | rel_to_abs_input_cutoff  | 2       | positive float  | The value relative to a predefined base-speed, at which `EV_REL` input (cursor and wheel) is considered at its maximum. |
      | release_timeout          | 0.05    | positive float  | The time `[s]` until a relative axis is considered stationary if no new events arrive                                   |

       

      ## CLI

      input-remapper-control --command requires the service to be running.

      systemctl start input-remapper
      sudo input-remapper-service

       

      Load all configured presets for all devices

      input-remapper-control --command autoload

       

      If you are running as root user, provide information about the whereabouts of the input-remapper config

      input-remapper-control --command autoload --config-dir "~/.config/input-remapper/"

       

      List available device names for the `--device` parameter

      sudo input-remapper-control --list-devices

       

      Stop injecting

      input-remapper-control --command stop --device "Razer Naga Trinity"

       

      Load ~/.config/input-remapper/presets/Razer Razer Naga Trinity/a.json

      input-remapper-control --command start --device "Razer Razer Naga Trinity" --preset "a"

       

      Loads the configured preset for whatever device is using this /dev path

      /bin/input-remapper-control --command autoload --device /dev/input/event5

       

      Stopping the service will stop all ongoing injections

      sudo systemctl stop input-remapper
      sudo systemctl start input-remapper
      systemctl status input-remapper

      Tester l’installation

      sudo input-remapper-service &
      input-remapper-control --command hello
      Connected to the service
      Daemon answered with "hello"
      Done 

       

      sudo input-remapper-control --list-devices

      Examples

      ## Event Names

      - Alphanumeric `a` to `z` and `0` to `9`

      - Modifiers `Alt_L` `Control_L` `Control_R` `Shift_L` `Shift_R`

      - Mouse buttons `BTN_LEFT` `BTN_RIGHT` `BTN_MIDDLE` `BTN_SIDE` …

      - Multimedia keys `KEY_NEXTSONG` `KEY_PLAYPAUSE` `XF86AudioMicMute` …

      - Mouse scroll `wheel(down, 10)` `wheel(up, 10)`

      - Mouse move `mouse(left, 1)` `mouse(right, 1)` `mouse(up, 1)` `mouse(down, 1)`

      Macros

      key(BTN_LEFT)-> un simple clic gauche de souris

      key(1).key(2)-> 1 puis 2

      repeat(3, key(a).w(500))-> a, a, a with 500ms pause

      modify(Control_L, key(a).key(x))-> CTRL + a puis CTRL + x

      key(1).hold(key(2)).key(3)-> writes 1 2 2 … 2 2 3 while the key is pressed

      event(EV_REL, REL_X, 10)-> moves the mouse cursor 10px to the right

      mouse(right, 4)-> which keeps moving the mouse while pressed

      wheel(down, 1)-> keeps scrolling down while held

      set(foo, 1)-> set ["foo"](https://en.wikipedia.org/wiki/Metasyntactic_variable) to 1

      if_eq($foo, 1, key(x), key(y))-> if "foo" is 1, write x, otherwise y

      hold()-> does nothing as long as your key is held down

      hold_keys(a)-> holds down "a" as long as the key is pressed, just like a regular non-macro mapping

      if_tap(key(a), key(b))-> writes a if the key is tapped, otherwise b

      if_tap(key(a), key(b), 1000)-> writes a if the key is released within a second, otherwise b

      if_single(key(a), key(b))-> writes b if another key is pressed, or a if the key is released and no other key was pressed in the meantime.

      if_tap(if_tap(key(a), key(b)), key(c))-> "a" if tapped twice, "b" if tapped once and "c" if held down long enough

      key_up(a).wait(1000).key_down(a)-> keeps a pressed for one second

      hold_keys(Control_L, a)-> holds down those two keys

      key(BTN_LEFT).wait(100).key(BTN_LEFT)-> a double-click

       

      ## Double Tap

      if_tap(
         if_tap(
            key(a),
            key(c)
         ),
         key(b)
      )

      - Si on appuie 2 fois > a

      - si on maintient la touche > b

      - si on appuie et relâche > c

       

      ## Combinations Spanning Multiple Devices

      **Keyboard** `space` `set(foo, 1).hold_keys(space).set(foo, 0)`

      **Mouse** `middle` `if_eq($foo, 1, hold_keys(a), hold_keys(BTN_MIDDLE))`

      Apply both presets. If you press space on your keyboard, it will write a space exactly like it used to. If you hold down space and press the middle button of your mouse, it will write "a" instead. If you just press the middle button of your mouse it behaves like a regular middle mouse button.

      Explications :

      hold_keys(space)makes your key work exactly like if it was mapped to "space". It will inject a key-down event if you press it, does  nothing as long you hold your key down, and injects a key-up event after releasing. `set(foo, 1).set(foo, 0)` sets "foo" to 1 and then sets "foo" to 0.

      `set` and `if_eq` work on shared memory, so all injections will see your variables. Combine both to get a key that works like a normal key, but that also works as a modifier for other keys of other devices. `if_eq($foo, 1, …, …)` runs the first param if foo is 1, or the second one if foo is not 1.

       

      ## Scroll and Click on a Keyboard

      - Print: `wheel(up, 1)` # PrintScreen

      - Pause: `wheel(down, 1)` # Pause

      - Scroll Lock: `BTN_LEFT` # ScrollLock

      - Menu: `BTN_RIGHT` #

      - F12: `KEY_LEFTCTRL + w`

      In contrast to libinput’s `ScrollMethod` `button` which requires the scroll button to belong to the same (mouse) device, clicking and scrolling events mapped to a keyboard key can fully cooperate with events from a real mouse, e.g. drag’n'drop by holding a (mapped) keyboard key and moving the cursor by mouse.

      Mapping the scrolling to a keyboard key is also useful for trackballs without a scroll ring.

      In contrast to a real scroll wheel, holding a key which has mouse wheel event mapped produces linear auto-repeat, without any acceleration. Using a PageDown key for fast scrolling requires only a small adjustment of the right hand position.

       

      ## Scroll on a 3-Button Mouse

      Cheap 3-button mouse without a scroll wheel can scroll using the middle button: - Button MIDDLE: `wheel(down, 1)`

       

      ## Click on Lower Buttons of Trackball

      Trackball with 4 buttons (e.g. Kensington Wireless Expert Mouse) with lower 2 buttons by default assigned to middle and side button can be remapped to provide left and right click on both the upper and lower pairs of buttons to avoid readjusting a hand after moving the cursor down:

       

      - Button MIDDLE: BTN_LEFT

      - Button SIDE: BTN_RIGHT

       

      ## Scroll on Foot Pedals

      While Kinesis Savant Elite 2 foot pedals can be programmed to emit key press or mouse click events, they cannot emit scroll events themselves. Using the pedals for scrolling while standing at a standing desk is possible thanks to remapping:

       

      - Button LEFT: `wheel(up, 1)`

      - Button RIGHT: `wheel(down, 1)`

       

      ## Gamepads

      Joystick movements will be translated to mouse movements, while the second joystick acts as a mouse wheel. You can swap this in the user interface. All buttons, triggers and D-Pads can be mapped to keycodes and macros.

       

      The D-Pad can be mapped to W, A, S, D for example, to run around in games, while the joystick turns the view (depending on the game).

       

      Tested with the XBOX 360 Gamepad. On Ubuntu, gamepads worked better in Wayland than with X11.

      Sequence of Keys with Modifiers

      Alt+TAB, Enter, Alt+TAB:

      modify(Alt_L, key(tab)).wait(250).
      key(KP_Enter).key(key_UP).wait(150).
      modify(Alt_L, key(tab))

      Emitting Unavailable Symbols

      For example Japanese letters without overwriting any existing key of your system-layout. Only works in X11.

      xmodmap -pke > keyboard_layout
      mousepad keyboard_layout &

       

      Find a code that is not mapped to anything, for example `keycode 93 = `, and map it like `keycode 93 = kana_YA`. See [this gist](https://gist.github.com/sezanzeb/e29bae637b8a799ccf2490b8537487df) for available symbols.

      xmodmap keyboard_layout
      input-remapper-gtk

       

      "kana_YA" should be in the dropdown of available symbols now. Map it to a key and press apply. Now run

      xmodmap keyboard_layout

       

      again for the injection to use that xmodmap as well. It should be possible to write "ヤ" now when pressing the key.

       

      can you explain me what conf files of input-remapper means?

       

      Device Identification: The configuration file will start by identifying the device for which the remapping is intended. This can include the device name, vendor ID, product ID, and other relevant details.

      [Device]
      name = "Your Device Name"
      vendor_id = 0x1234
      product_id = 0x5678

       

      Key/Button Remapping: This section specifies which keys or buttons should be remapped to other keys or buttons. Each remapping rule will typically include the original key/button and the new key/button it should map to.

      [Mappings]
      KEY_A = KEY_B
      BTN_LEFT = BTN_RIGHT

       

      Modifiers and Combinations : Sometimes, you might want to remap combinations of keys or buttons. This section allows for specifying such combinations.

      [Modifiers]
      CTRL+KEY_A = KEY_C
      ALT+BTN_LEFT = BTN_MIDDLE

       

      Advanced Options: Advanced remapping options might include delays, sequences, or conditional mappings. These settings can provide more fine-grained control over the input behavior.

      [Advanced]
      delay = 50  # milliseconds
      sequence = KEY_A, KEY_B, KEY_C

       

      Profiles: Some tools support multiple profiles, allowing users to switch between different sets of remappings easily. This section would define different profiles and their respective mappings.

      [Profiles]
      profile1 = "Gaming"
      profile2 = "Editing"
      
      [Gaming]
      KEY_W = KEY_UP
      KEY_S = KEY_DOWN
      
      [Editing]
      KEY_W = KEY_HOME
      KEY_S = KEY_END

       

      Comments and Documentation: Like many configuration files, these files can also include comments to document the purpose of each remapping. Comments are usually prefixed by a #.

      # This remaps the 'A' key to 'B'
      KEY_A = KEY_B

       

      example of a simple configuration file for input-remapper:

      [Device]
      name = "Generic Keyboard"
      vendor_id = 0x1234
      product_id = 0x5678
      
      [Mappings]
      KEY_A = KEY_B  # Remap 'A' to 'B'
      KEY_LEFT = KEY_RIGHT  # Remap 'Left Arrow' to 'Right Arrow'
      
      [Modifiers]
      CTRL+KEY_A = KEY_C  # Remap 'Ctrl+A' to 'C'
      
      [Advanced]
      delay = 100  # 100ms delay between key presses
      sequence = KEY_X, KEY_Y, KEY_Z  # Sequence of keys
      
      [Profiles]
      profile1 = "Work"
      profile2 = "Play"
      
      [Work]
      KEY_W = KEY_UP
      KEY_S = KEY_DOWN
      
      [Play]
      KEY_W = KEY_HOME
      KEY_S = KEY_END

      In this example, the configuration file defines a generic keyboard with specific remappings for individual keys, key combinations, and advanced options like delays and sequences. Additionally, it supports multiple profiles for different use cases (e.g., "Work" and "Play").

       

      This structured approach allows users to tailor their input devices’ behavior to their preferences and needs, making the input-remapper a versatile tool for customizing input on Linux systems.

      but my conf is in json format!

       

      Got it! When the configuration for input-remapper is in JSON format, it follows a similar structure but uses JSON syntax. Here’s an explanation of the different sections you might find in a JSON configuration file for input-remapper and an example to illustrate:

      Sections of a JSON Configuration File

       

      Device Identification: Identifies the device for which the remapping is intended. This includes the device name, vendor ID, product ID, and other details.

      {
      "device": {
      "name": "Your Device Name",
      "vendor_id": 4660,
      "product_id": 22136
      }
      }

       

      Key/Button Remapping: Specifies which keys or buttons should be remapped to other keys or buttons. Each remapping rule includes the original key/button and the new key/button.

      {
      "mappings": {
      "KEY_A": "KEY_B",
      "BTN_LEFT": "BTN_RIGHT"
      }
      }

       

      Modifiers and Combinations: Allows for remapping combinations of keys or buttons.

      {
      "modifiers": {
      "CTRL+KEY_A": "KEY_C",
      "ALT+BTN_LEFT": "BTN_MIDDLE"
      }
      }

       

      Advanced Options: Includes advanced remapping options like delays, sequences, or conditional mappings.

      {
        "advanced": {
          "delay": 50,
          "sequence": ["KEY_A", "KEY_B", "KEY_C"]
        }
      }

       

      Profiles: Supports multiple profiles, allowing users to switch between different sets of remappings easily.

      {
        "profiles": {
          "profile1": {
            "name": "Gaming",
            "mappings": {
              "KEY_W": "KEY_UP",
              "KEY_S": "KEY_DOWN"
            }
          },
          "profile2": {
            "name": "Editing",
            "mappings": {
              "KEY_W": "KEY_HOME",
              "KEY_S": "KEY_END"
            }
          }
        }
      }

       

      Example JSON Configuration File

      {
      "device": {
        "name": "Generic Keyboard",
        "vendor_id": 4660,
        "product_id": 22136
      },
      "mappings": {
        "KEY_A": "KEY_B",
        "KEY_LEFT": "KEY_RIGHT"
      },
      "modifiers": {
        "CTRL+KEY_A": "KEY_C"
      },
      "advanced": {
        "delay": 100,
        "sequence": ["KEY_X", "KEY_Y", "KEY_Z"]
      },
      "profiles": {
        "profile1": {
          "name": "Work",
          "mappings": {
            "KEY_W": "KEY_UP",
            "KEY_S": "KEY_DOWN"
          }
        },
        "profile2": {
          "name": "Play",
          "mappings": {
            "KEY_W": "KEY_HOME",
            "KEY_S": "KEY_END"
          }
        }
      }
      }

       

      Explanation of the Example

      Device: Specifies a generic keyboard with a vendor ID of 4660 and a product ID of 22136.

      Mappings: Remaps the A key to B and the Left Arrow key to Right Arrow.

      Modifiers: Remaps the combination Ctrl+A to C.

      Advanced: Sets a delay of 100 milliseconds between key presses and defines a sequence of keys (X, Y, Z).

      Profiles: Defines two profiles:

      Work: Remaps W to Up Arrow and S to Down Arrow.

      Play: Remaps W to Home and S to End.

       

      what "1,41,1″ means in this file?

       

      La sequence "1,41,1" veut dire type, code, value:

      Type: EV_KEY type of input event (key press, key release).

      Code: the specific key or button being referenced. 41 corresponds to the KEY_S

      Value: state or value of the event (pressed, released, held down). For keys, 1 = key pressed, 0 = key released, 2 = key held down.

       

      {
        "device": {
          "name": "Generic Keyboard",
          "vendor_id": 4660,
          "product_id": 22136
        },
        "mappings": {
          "1,41,1": "1,30,1"  # Remap 'S' key press to 'A' key press
        },
        "modifiers": {
          "1,29,1,1,41,1": "1,46,1"  # Remap 'Ctrl+S' press to 'C' key press
        }
      }

       

      Mappings: "1,41,1″: "1,30,1″ remaps the press event of the S key (code 41) to the press event of the A key (code 30).

      Modifiers: "1,29,1,1,41,1″: "1,46,1″ remaps the combination of Ctrl (code 29) pressed and S (code 41) pressed to the C key press (code 46).

       

      Mapping Key Codes

      some common key codes for reference:

      KEY_A: 30
      KEY_B: 48
      KEY_C: 46
      KEY_S: 31
      KEY_LEFTCTRL: 29
      BTN_LEFT: 272

       

      Key code 41 corresponds to the KEY_F key.

       

      This mapping is part of the standard Linux input event codes, which can be found in the header files such as /usr/include/linux/input-event-codes.h on Linux systems.

       

      Using showkey or evtest in Linux

      sudo apt-get install console-tools evtest

       

      Use showkey:

      sudo showkey --scancodes

      Press the square bracket key ([), and observe the scancode that is printed.

       

      Use evtest:

      sudo evtest

      Select your keyboard device from the list and press the square bracket key ([), then observe the key code printed.

       

      Example JSON Configuration File for AZERTY Keyboard

      {
      "device": {
      "name": "Generic AZERTY Keyboard",
      "vendor_id": 4660,
      "product_id": 22136
      },
      "mappings": {
      "1,26,1": "1,30,1"  # Remap '[' key press to 'A' key press
      },
      "modifiers": {
      "1,29,1,1,26,1": "1,46,1"  # Remap 'Ctrl+[' press to 'C' key press
      }
      }

       

      Device: Identifies the device being remapped.

      Mappings: "1,26,1": "1,30,1": Remaps the [ key press (key code 26) to the A key press (key code 30).

      Modifiers: "1,29,1,1,26,1": "1,46,1": Remaps the combination of Ctrl (key code 29) and [ (key code 26) press to the C key press (key code 46).

       

       

      Key Code for the Œ Key On a French AZERTY keyboard, the Œ key is usually located at the same position as the 2 key in the top row when AltGr is used. The key code for Œ on a French AZERTY layout is commonly 47 for KEY_OEM_102 (ISO key).

      {
      "device": {
      "name": "Generic AZERTY Keyboard",
      "vendor_id": 4660,
      "product_id": 22136
      },
      "mappings": {
      "1,47,1": "1,30,1"  # Remap 'Œ' key press to 'A' key press
      },
      "modifiers": {
      "1,29,1,1,47,1": "1,46,1"  # Remap 'Ctrl+Œ' press to 'C' key press
      }
      }

       

      If showkey does not display the correct key code for the Œ key, you can try using xev, which is a more detailed utility for X11 environments that shows the key events, including key codes and keysyms. Here’s how you can use xev to determine the key code for the Œ key on your AZERTY keyboard:

       

      Install xev (if not already installed):

      sudo apt-get install x11-utils

       

      Run xev:

      xev

       

      Find the Key Code: A small window will appear. Focus on this window and press the Œ key.

      Look at the terminal where you launched xev. You should see output similar to this when you press the key:

      KeyPress event, serial 37, synthetic NO, window 0x3a00001,
      root 0x1a2, subw 0x0, time 12345678, (100,100), root:(200,200),
      state 0x0, keycode 47 (keysym 0x1000152, OE), same_screen YES,
      XLookupString gives 2 bytes: (c5 92) "Œ"
      XmbLookupString gives 2 bytes: (c5 92) "Œ"
      XFilterEvent returns: False

       

      In this output, keycode 47 is the key code for the Œ key, and keysym 0x1000152 corresponds to the Œ character.

       

      what are keysyms?

       

      Keysyms (Key Symbols) are part of the X Window System, which is a framework for managing graphical user interfaces on UNIX-like operating systems, including Linux. They represent the symbolic names for keyboard keys, which can correspond to characters, control functions, or other symbols. Keysyms abstract the physical key codes to allow applications to interpret keyboard input in a way that is independent of the specific keyboard layout.

      Key Concepts

       

      Key Codes: These are numerical representations of physical keys on the keyboard. Key codes are hardware-specific and indicate which key is pressed.

      Keysyms: These are symbolic names that represent the meaning or function of a key press. Keysyms map to characters or control functions and are more abstract than key codes. They are defined by the X Window System.

      Mapping Key Codes to Keysyms: The X server maps key codes to keysyms based on the current keyboard layout. This allows the same key code to produce different keysyms depending on the layout (e.g., QWERTY, AZERTY).

       

      Examples

      Here are a few examples to illustrate the relationship between key codes and keysyms:

      Key Code 38:

      QWERTY Layout: keysym 0x0061 (a)

      AZERTY Layout: keysym 0x0071 (a)

      Key Code 26:

      QWERTY Layout: keysym 0x005b ([)

      AZERTY Layout: keysym 0x00e9 (é)

      Key Code 47:

      QWERTY Layout: keysym 0x0063 (c)

      AZERTY Layout: keysym 0x0152 (Œ)

       

      Using xev to Identify Keysyms

      sudo apt-get install x11-utils

       

      Run xev:

      xev

       

      Press the Key: A small window will appear. Press the key you want to identify (e.g., the Œ key).

      Observe the Output: The terminal will display information about the key press event, including the key code and keysym.

      Example output for the Œ key:

      KeyPress event, serial 37, synthetic NO, window 0x3a00001,
      root 0x1a2, subw 0x0, time 12345678, (100,100), root:(200,200),
      state 0x0, keycode 47 (keysym 0x1000152, OE), same_screen YES,
      XLookupString gives 2 bytes: (c5 92) "Œ"
      XmbLookupString gives 2 bytes: (c5 92) "Œ"
      XFilterEvent returns: False

       

      KeyPress event: Indicates a key press event.

      keycode 47: The key code for the pressed key.

      keysym 0x1000152 (OE): The keysym for the Œ character, represented by the hexadecimal value 0x1000152.

       

      Using Keysyms in Input-Remapper

      In the context of configuring an input-remapper, understanding keysyms is crucial for correctly mapping keys. For instance, if you want to remap the Œ key to another key, you need to know both the key code and the corresponding keysym.

      {
      "device": {
      "name": "Generic AZERTY Keyboard",
      "vendor_id": 4660,
      "product_id": 22136
      },
      "mappings": {
      "1,47,1": "1,30,1"  # Remap 'Œ' key press (keycode 47) to 'A' key press (keycode 30)
      },
      "modifiers": {
      "1,29,1,1,47,1": "1,46,1"  # Remap 'Ctrl+Œ' press to 'C' key press (keycode 46)
      }
      }

       

      how to know all keycode corresponding to keysyms in one time of my keyboard?

      To determine all key codes and their corresponding keysyms for your keyboard in one go, you can use the xmodmap utility, which is available on most UNIX-like systems that use the X Window System. xmodmap can print out the current keymap, which includes both key codes and their associated keysyms.

       

      Using xmodmap to List Key Codes and Keysyms

       

      Install xmodmap :

      sudo apt-get install x11-xserver-utils

       

      List the Keymap:

      xmodmap -pke

       

      This command will print the current keymap to the terminal. Each line in the output represents a key code and the keysyms associated with it. The output will look something like this:

      keycode  24 = a A a A
      keycode  25 = z Z z Z
      keycode  26 = e E e E
      ...
      keycode  32 = o O o O
      keycode  33 = p P p P
      keycode  34 = bracketleft braceleft bracketleft braceleft
      keycode  35 = bracketright braceright bracketright braceright
      keycode  36 = Return NoSymbol Return
      ...
      keycode  47 = oe OE oe OE

       

      keycode: The numerical representation of the physical key on the keyboard.

      keysyms: The symbolic names for the key’s output, which can include different characters depending on modifiers like Shift, AltGr, etc.

       

      For example:

      keycode 24 = a A a A: The key with keycode 24 produces a when pressed normally, A when pressed with Shift, and repeats for other modifier states.

      keycode 47 = oe OE oe OE: The key with keycode 47 produces œ when pressed normally and Œ when pressed with Shift.

       

      Saving the Output to a File

      If you want to save this output to a file for easier reference, you can redirect the output to a file:

      xmodmap -pke > keymap.txt

       

      and the keycode of the key on the left of "&" key on a azerty keyboard

      On a French AZERTY keyboard, the key to the left of the & key (which is 1 when Shift is not pressed) is the ² key. This key doesn't have a direct equivalent in many other keyboard layouts and is often used to type the superscript two symbol (²).

      To find the key code for this key, you can use xev to see the detailed information for the key press event.

      Using xev to Identify the Key Code

       

      Install xev (if not already installed):

      sudo apt-get install x11-utils

       

      Run xev:

      xev

       

      Press the Key: A small window will appear. Focus on this window and press the ² key (the key to the left of & on your AZERTY keyboard).

      Look at the terminal where you launched xev. You should see output similar to this when you press the ² key:

      KeyPress event, serial 37, synthetic NO, window 0x3a00001,
      root 0x1a2, subw 0x0, time 12345678, (100,100), root:(200,200),
      state 0x0, keycode 49 (keysym 0x0, NoSymbol), same_screen YES,
      XLookupString gives 1 bytes: (b2) "²"
      XmbLookupString gives 1 bytes: (b2) "²"
      XFilterEvent returns: False

       

      keycode 49: This indicates that the key code for the ² key is 49.

      Once you have identified the key code, you can use it in your input-remapper configuration file. Here’s an example:

      {
      "device": {
      "name": "Generic AZERTY Keyboard",
      "vendor_id": 4660,
      "product_id": 22136
      },
      "mappings": {
      "1,49,1": "1,30,1"  # Remap '²' key press to 'A' key press
      },
      "modifiers": {
      "1,29,1,1,49,1": "1,46,1"  # Remap 'Ctrl+²' press to 'C' key press
      }
      }

       

      Explanation of the Example

      Device: Identifies the device being remapped.

      Mappings:"1,49,1": "1,30,1": Remaps the ² key press (key code 49) to the A key press (key code 30).

      Modifiers:"1,29,1,1,49,1": "1,46,1": Remaps the combination of Ctrl (key code 29) and ² (key code 49) press to the C key press (key code 46).

       

      no, i mean the "windows" key

      The key typically located between the Ctrl and Alt keys on a standard keyboard, often referred to as the "Windows" key, is also known as the "Super" key in Linux environments. This key is usually used to trigger system shortcuts and other functions in various operating systems.

      To find the key code for the "Windows" or "Super" key, you can follow the same steps using the xev tool:

      Using xev to Identify the Key Code for the "Super" Key

       

      Install xev (if not already installed):

      sudo apt-get install x11-utils

       

      Run xev

      xev

       

      Press the Key:A small window will appear. Focus on this window and press the "Windows" or "Super" key.

      KeyPress event, serial 37, synthetic NO, window 0x3a00001,
      root 0x1a2, subw 0x0, time 12345678, (100,100), root:(200,200),
      state 0x0, keycode XX (keysym 0xffeb, Super_L), same_screen YES,
      XLookupString gives 0 bytes:
      XmbLookupString gives 0 bytes:
      XFilterEvent returns: False

       

      {
        "device": {
          "name": "Generic Keyboard",
          "vendor_id": 4660,
          "product_id": 22136
        },
        "mappings": {
          "1,XX,1": "1,30,1"  # Remap 'Super' key press to 'A' key press
        },
        "modifiers": {
          "1,29,1,1,XX,1": "1,46,1"  # Remap 'Ctrl+Super' press to 'C' key press
        }
      }

       

      but keycode with xev is not the same with input_remapper ?

      You're correct. The keycodes reported by xev may not always directly correspond to the keycodes used by input-remapper or other system utilities. The discrepancy arises because xev reports the X11 keycode, which is specific to the X Window System, while input-remapper may use a different keycode system, such as the Linux input event keycode.

       

      To obtain the keycode that input-remapper recognizes for remapping, you would need to consult the documentation or configuration of input-remapper or use tools specific to that utility.

       

      For input-remapper, you can often find the keycode mappings in its configuration file or documentation. If you're uncertain about the mapping, you may need to experiment by remapping a key to a known keycode and observing the behavior.

       

      Here's a general approach to find the keycode for the "Windows" or "Super" key using input-remapper:

       

      Open the input-remapper configuration file.

      Look for any existing mappings or configurations related to the "Windows" or "Super" key.

      If there are no existing mappings, you may need to add a new mapping and specify the keycode for the "Windows" or "Super" key. You can then observe the effect of this mapping to identify the keycode.

      Save the configuration file and restart input-remapper if necessary to apply the changes.

      Test the remapping to ensure it behaves as expected.

       

      If you're still unsure or unable to find the appropriate keycode, you may need to consult the documentation or support resources specific to input-remapper or seek assistance from its community or developers.

      xdotool

      sudo apt install xdotool

      ---

      Liste des touches

      SOURIS

      LButton bouton gauche. To always perform a logical left click, use Click Left or Send {Click Left}.

      RButton bouton droite. To always perform a logical right click, use Click Right or Send {Click Right}.

      MButton Middle or wheel mouse button

      XButton1 4th mouse button. Typically performs the same function as Browser_Back.

      XButton2 5th mouse button. Typically performs the same function as Browser_Forward.

      WheelDown Turn the wheel downward (toward you).

      WheelUp Turn the wheel upward (away from you).

      WheelLeft

      WheelRight

      TOUCHES NORMALES

      Le nom des touches de Lettres et Chiffres sont b pour la touche B, 5 pour 5.

      The letters a-z or A-Z can be used to refer to the corresponding virtual keycodes (usually vk41-vk5A) even if they are not included in the current keyboard layout.

      CapsLock Verrou Maj

      Space barre d'espace

      Tab Touche Tabulation

      Enter Entrée -> Return Déprécié. Choisir plutôt Enter.

      Escape (ou Esc) Echap

      Backspace (ou BS) Backspace

      Touches de curseur

      ScrollLock (scroll lock key). While Ctrl is held down, ScrollLock produces the key code of CtrlBreak, but can be differentiated from Pause by scan code.

      Delete (or Del) Del

      Insert (or Ins) Ins

      Home Home/Début

      End End/Fin

      PgUp Page haut - PgDn Page bas

      Up ↑ (flèche haut) -Down ↓ (flèche bas) - Left ← (flèche gauche) - Right → (flèche droite)

      Pavé numérique

      Numpad0 / NumpadIns 0 / Ins

      Numpad1 / NumpadEnd 1 / End

      Numpad2 / NumpadDown 2 / ↓

      Numpad3 / NumpadPgDn 3 / PgDn

      Numpad4 / NumpadLeft 4 / ←

      Numpad5 / NumpadClear 5 / typically does nothing

      Numpad6 / NumpadRight 6 / →

      Numpad7 / NumpadHome 7 / Home

      Numpad8 / NumpadUp 8 / ↑

      Numpad9 / NumpadPgUp 9 / PgUp

      NumpadDot / NumpadDel . / Del

      NumLock NumLock. While Ctrl is held down, NumLock produces the key code of Pause, so use ^Pause in hotkeys instead of ^NumLock.

      NumpadDiv / (division)

      NumpadMult * (multiplication)

      NumpadAdd + (addition)

      NumpadSub - (subtraction)

      NumpadEnter Enter

       

      Si NumLock is OFF but Shift is pressed, the system temporarily releases Shift and acts as though NumLock is ON.

      F..

      F1 à F12 et F1 à F24 si clavier possède plus.

      Modificateurs

      Super_L Windows gauche. Correspond à <# hotkey prefix.

      Super_R Windows droite. Correspond à ># hotkey prefix.

      Hotkeys with the # modifier can be triggered by either Win.

      Control (or Ctrl) Ctrl. As a hotkey (Control::) it fires upon release unless it has the tilde prefix. Corresponds to the ^ hotkey prefix.

      Alt Alt. As a hotkey (Alt::) it fires upon release unless it has the tilde prefix. Corresponds to the ! hotkey prefix.

      Shift Shift. As a hotkey (Shift::) it fires upon release unless it has the tilde prefix. Corresponds to the + hotkey prefix.

      LControl (or LCtrl) Left Ctrl. Corresponds to the <^ hotkey prefix.

      RControl (or RCtrl) Right Ctrl. Corresponds to the >^ hotkey prefix.

      LShift Left Shift. Corresponds to the <+ hotkey prefix.

      RShift Right Shift. Corresponds to the >+ hotkey prefix.

      LAlt Left Alt. Corresponds to the <! hotkey prefix.

      RAlt Right Alt. Corresponds to the >! hotkey prefix.

      Note: Si AltGr au lieu de RAlt, you can probably use it as a hotkey prefix via <^>! as described here. In addition, LControl & RAlt:: would make AltGr itself into a hotkey.

      Multimédia

      Browser_Back Back

      Browser_Forward Forward

      Browser_Refresh Refresh

      Browser_Stop Stop

      Browser_Search Search

      Browser_Favorites Favorites

      Browser_Home Homepage

      Volume_Mute Mute the volume

      Volume_Down Lower the volume

      Volume_Up Increase the volume

      Media_Next Next Track

      Media_Prev Previous Track

      Media_Stop Stop

      Media_Play_Pause Play/Pause

      Launch_Mail Launch default e-mail program

      Launch_Media Launch default media player

      Launch_App1 Launch This PC (formerly My Computer or Computer)

      Launch_App2 Launch Calculator

      Autres

      AppsKey Menu. This is the key that invokes the right-click context menu.

      PrintScreen PrtSc (print screen key)

      CtrlBreak Ctrl+Pause or Ctrl+ScrollLock

      Pause Pause or Ctrl+NumLock. While Ctrl is held down, Pause produces the key code of CtrlBreak and NumLock produces Pause, so use ^CtrlBreak in hotkeys instead of ^Pause.

      Break Deprecated: Use the synonym Pause instead.

      Help Help. This probably doesn't exist on most keyboards. It's usually not the same as F1.

      Sleep Sleep. Note that the sleep key on some keyboards might not work with this.

      SCnnn Specify for nnn the scan code of a key. Recognizes unusual keys not mentioned above. See Special Keys for details.

      VKnn Specify for nn the hexadecimal virtual key code of a key. This rarely-used method also prevents certain types of hotkeys from requiring the keyboard hook. For example, the following hotkey does not use the keyboard hook, but as a side-effect it is triggered by pressing either Home or NumpadHome:

      ^VK24::MsgBox You pressed Home or NumpadHome while holding down Control.

      Known limitation: VK hotkeys that are forced to use the keyboard hook, such as *VK24 or ~VK24, will fire for only one of the keys, not both (e.g. NumpadHome but not Home). For more information about the VKnn method, see Special Keys.

      Warning: Only Send, GetKeyName(), GetKeyVK(), GetKeySC() and #MenuMaskKey support combining VKnn and SCnnn. [v1.1.27+]: The presence of an invalid suffix prevents VKnn from being recognized. For example, vk1Bsc001:: raises an error in v1.1.27+, but sc001 was ignored (had no effect) in previous versions.

      Joystick, manettes

      Joy joystick et manettes

      Joy1 à Joy32: Les boutons. Pour connaitre le bouton associé au numéro : voir ce script. Note that hotkey prefix symbols such as ^ (control) and + (shift) are not supported. Also note that the pressing of controller buttons always "passes through" to the active window if that window is designed to detect the pressing of controller buttons.

      Although the following control names cannot be used as hotkeys, they can be used with GetKeyState:
      JoyX, JoyY, and JoyZ: The X (horizontal), Y (vertical), and Z (altitude/depth) axes of the stick.

      JoyR: The rudder or 4th axis of the stick.

      JoyU and JoyV: The 5th and 6th axes of the stick.

      JoyPOV: The point-of-view (hat) control.

      JoyName: The name of the controller or its driver.

      JoyButtons: The number of buttons supported by the controller (not always accurate).

      JoyAxes: The number of axes supported by the controller.

      JoyInfo: Provides a string consisting of zero or more of the following letters to indicate the controller’s capabilities: Z (has Z axis), R (has R axis), U (has U axis), V (has V axis), P (has POV control), D (the POV control has a limited number of discrete/distinct settings), C (the POV control is continuous/fine). Example string: ZRUVPD

      Ex avec Xbox Wireless/360, JoyX/JoyY is the left stick, JoyR/JoyU the right stick, JoyZ the left and right triggers, and JoyPOV the directional pad (D-pad).

      Multiple controllers: If the computer has more than one controller and you want to use one beyond the first, include the controller number (max 16) in front of the control name. For example, 2joy1 is the second controller’s first button.

      Note: If you have trouble getting a script to recognize your controller, specify a controller number other than 1 even though only a single controller is present. It is unclear how this situation arises or whether it is normal, but experimenting with the controller number in the controller test script can help determine if this applies to your system.
      >Controller remapping: Methods of sending keystrokes and mouse clicks with a controller.

      >Controller-To-Mouse script: Using a controller as a mouse.

      xmodmap

      This shows all keys with their numbers/names

      xmodmap -pk

      This swaps the Delete and Insert key

      xmodmap -e "keycode 118 = Delete"
      xmodmap -e "keycode 119 = Insert"

      To switch it back

      >#xmodmap -e "keycode 118 = Insert"
      #xmodmap -e "keycode 119 = Delete"

       

      This shows all keys with their numbers/names

      xmodmap -pk

       

      This swaps the Delete and Insert key

      xmodmap -e "keycode 118 = Delete"
      xmodmap -e "keycode 119 = Insert"

       

      To switch it back

      #xmodmap -e "keycode 118 = Insert"
      #xmodmap -e "keycode 119 = Delete"

       

      Disable/reconfigure keyboard multimedia keys

      XKB Method

      Edit the XKB /usr/share/X11/xkb/symbols/pc file by running the following command in the terminal:

      sudo nano /usr/share/X11/xkb/symbols/pc

       

      Find lines that contain XF86 like so:

      key <KEY_CODE> { [ XF86MonBrightnessDown ] };

       

      Comment them out by adding // before them like so:

      //key <KEY_CODE> { [ XF86MonBrightnessDown ] };

       

      Save the file and exit the editor by pressing Ctrl + X then press Y.

       

      Clear the XKB cache by running the following command in the terminal:

      sudo rm -rf /var/lib/xkb/*

       

      Reboot your system to activate your new XKB configuration or alternatively you can avoid reboot and try to reload the new XKB configuration by setting an XKB map layout using the following command in the terminal:

      setxkbmap -layout us

       

      Test your keys.

      If the keyboard multimedia keys are configured by the manufacturer to report a single key code, the above solution might disable them and leave the keys free to be used for other purposes.

      If, however, this is not the case, then you will need to deal with xmodmap.

      xmodmap Method

      you cannot just disable multimedia keys using this method and assign them to nothing like so xmodmap -e ‘keycode Number =’ because this, oftentimes, will render them unusable so you will need to reassign them to the desired functions. You will also need to put in action some mechanism to maintain your changes between reboots and logouts/logins.

      To implement this method, please follow the steps below:

       

      Show the current keyboard map by running the following command in the terminal:

      xmodmap -pke

       

      Inspect the output and identify lines that contain XF68 right after the = sign like so:

      keycode 232 = XF86MonBrightnessDown NoSymbol XF86MonBrightnessDown NoSymbol XF86MonBrightnessDown

       

      The above line, for example, shows that the key with code number 232 is currently configured to trigger XF86MonBrightnessDown which will decrease the monitor’s brightness and you can change this behavior by assigning a different value to it like so xmodmap -e ‘keycode 232 = New_Value’. For example to assign the F11 functionality to this multimedia key, please run the following command in the terminal:

      xmodmap -e 'keycode 232 = F11'

       

      The new functionality will be effective immediately. This change in functionality will, however, be lost after reboot or logout/login.

       

      Notice: It might be helpful to run the acpi_listen command in the terminal and monitor the output as you press the actual physical key then compare it to the output you got from xmodmap -pke so that you confirm the key code is for the one you want. You can also try the xev utility but, unfortunately it will not always return a key code when dealing with multimedia or vendor specific keys.

       

      To preserve the change after reboots and logouts/logins, you will need to do the following:

       

      Create and edit a script file in your home directory by running the following command in the terminal:

      nano ~/.Modify_Multimedia_Keys.sh

       

      Add this #!/bin/bash in the first line then add your xmodmap -e ‘keycode Number = New_Value’ commands below the first line ( each command in a single new line ) like so:

      #!/bin/bash
      xmodmap -e 'keycode 232 = F11'
      xmodmap -e 'keycode 122 = F2'

       

      Save the script file and exit the editor by pressing Ctrl + X then press Y.

      Make the script file executable by running the following command in the terminal:

      chmod +x ~/.Modify_Multimedia_Keys.sh

       

      Make the script file execute at each start-up either by adding it to your Startup Applications through the GUI or by placing a Modify_Multimedia_Keys.desktop file in the ~/.config/autostart/ directory that contains the following content replacing YOUR_USERNAME with your actual username:

      [Desktop Entry]
      Type=Application
      Exec=/home/YOUR_USERNAME/.Modify_Multimedia_Keys.sh
      Hidden=false
      X-GNOME-Autostart-enabled=true
      Name=Modify Multimedia Keys
      Comment=This modifies keyboard multimedia keys

       

      XFree86 vendor specific keysyms.

      /*
      * The XFree86 keysym range is 0x10080001 - 0x1008FFFF.
      */
      
      /*
      * ModeLock
      *
      * This one is old, and not really used any more since XKB offers this functionality.
      */
      
      #define XF86XK_ModeLock		0x1008FF01	/* Mode Switch Lock */
      
      /* Backlight controls. */
      #define XF86XK_MonBrightnessUp   0x1008FF02  /* Monitor/panel brightness */
      #define XF86XK_MonBrightnessDown 0x1008FF03  /* Monitor/panel brightness */
      #define XF86XK_KbdLightOnOff     0x1008FF04  /* Keyboards may be lit     */
      #define XF86XK_KbdBrightnessUp   0x1008FF05  /* Keyboards may be lit     */
      #define XF86XK_KbdBrightnessDown 0x1008FF06  /* Keyboards may be lit     */
      
      /*
      * Keys found on some "Internet" keyboards.
      */
      
      #define XF86XK_Standby		0x1008FF10   /* System into standby mode   */
      #define XF86XK_AudioLowerVolume	0x1008FF11   /* Volume control down        */
      #define XF86XK_AudioMute	0x1008FF12   /* Mute sound from the system */
      #define XF86XK_AudioRaiseVolume	0x1008FF13   /* Volume control up          */
      #define XF86XK_AudioPlay	0x1008FF14   /* Start playing of audio >   */
      #define XF86XK_AudioStop	0x1008FF15   /* Stop playing audio         */
      #define XF86XK_AudioPrev	0x1008FF16   /* Previous track             */
      #define XF86XK_AudioNext	0x1008FF17   /* Next track                 */
      #define XF86XK_HomePage		0x1008FF18   /* Display user's home page   */
      #define XF86XK_Mail		0x1008FF19   /* Invoke user's mail program */
      #define XF86XK_Start		0x1008FF1A   /* Start application          */
      #define XF86XK_Search		0x1008FF1B   /* Search                     */
      #define XF86XK_AudioRecord	0x1008FF1C   /* Record audio application   */
      
      /* Some more "Internet" keyboard symbols */
      #define XF86XK_Back		0x1008FF26   /* Like back on a browser     */
      #define XF86XK_Forward		0x1008FF27   /* Like forward on a browser  */
      #define XF86XK_Stop		0x1008FF28   /* Stop current operation     */
      #define XF86XK_Refresh		0x1008FF29   /* Refresh the page           */
      #define XF86XK_PowerOff		0x1008FF2A   /* Power off system entirely  */
      #define XF86XK_WakeUp		0x1008FF2B   /* Wake up system from sleep  */
      #define XF86XK_Eject            0x1008FF2C   /* Eject device (e.g. DVD)    */
      #define XF86XK_ScreenSaver      0x1008FF2D   /* Invoke screensaver         */
      #define XF86XK_WWW              0x1008FF2E   /* Invoke web browser         */
      #define XF86XK_Sleep            0x1008FF2F   /* Put system to sleep        */
      #define XF86XK_Favorites	0x1008FF30   /* Show favorite locations    */
      #define XF86XK_AudioPause	0x1008FF31   /* Pause audio playing        */
      #define XF86XK_AudioMedia	0x1008FF32   /* Launch media collection app */
      #define XF86XK_MyComputer	0x1008FF33   /* Display "My Computer" window */
      #define XF86XK_VendorHome	0x1008FF34   /* Display vendor home web site */
      #define XF86XK_LightBulb	0x1008FF35   /* Light bulb keys exist       */
      #define XF86XK_Shop		0x1008FF36   /* Display shopping web site   */
      #define XF86XK_History		0x1008FF37   /* Show history of web surfing */
      #define XF86XK_OpenURL		0x1008FF38   /* Open selected URL           */
      #define XF86XK_AddFavorite	0x1008FF39   /* Add URL to favorites list   */
      #define XF86XK_HotLinks		0x1008FF3A   /* Show "hot" links            */
      #define XF86XK_BrightnessAdjust	0x1008FF3B   /* Invoke brightness adj. UI   */
      #define XF86XK_Launch3		0x1008FF43   /* Launch Application          */
      #define XF86XK_Launch4		0x1008FF44   /* Launch Application          */
      #define XF86XK_Ungrab		0x1008FE20   /* force ungrab               */
      #define XF86XK_ClearGrab	0x1008FE21   /* kill application with grab */
      #define XF86XK_Next_VMode	0x1008FE22   /* next video mode available  */
      #define XF86XK_Prev_VMode	0x1008FE23   /* prev. video mode available */
      #define XF86XK_LogWindowTree	0x1008FE24   /* print window tree to log   */
      #define XF86XK_LogGrabInfo	0x1008FE25   /* print all active grabs to log */

      However, the version in this repository lags a bit behind the current version. For example, the version available for Ubuntu 22.04 (the latest LTS), is 1.4.0, while the latest version (at the time of writing this post) is 2.0.1. To install the latest version, according to the project’s README, run these commands (adjust appropriately for the latest version):

       

      sudo apt install git python3-setuptools gettext
      git clone https://github.com/sezanzeb/input-remapper.git
      cd input-remapper && ./scripts/build.sh
      sudo apt install -f ./dist/input-remapper-2.0.1.deb

      xmodmap

      Pour e remapping et changer les modifiers.

       

      xmodmap -e "your commands"

       

      ou dans le fichier .xmodmaprc, à exécuter via .bashrc:

      xmodmap .xmodmaprc

      If you name the file ~/.xmodmap it will be executed automatically on login.

       

      Now the commands

      First unmap Super from its modifier, then you map it to control.

       

      Liste of the bound modifiers -> Super is referred to as mod4. Super_L and Super_R are separate keys which output the same modifier.

      xmodmap -pm

       

      Now you can unmap the modifier from it. Run the xmodmap command (using one of the methods above)

      xmodmap -e "remove mod4 = Super_L"

       

      Now the physical key is still referred to internally as Super_L, but it doesn’t do anything.

       

      Now just remap it. Run the xmodmap command:

      xmodmap -e "add control = Super_L"

       

      If you want to undo this later on, just run the same commands with the appropriate arguments.

       

      No Super_R?

      The output of xmodmap -pm might given you several keys named Super_L but none named Super_R. If it did, you now have several extra keys assigned to Control, but none assigned to Super. You’ll have to rename one key. (NB: it might give you several Super_L and at least one Super_R. This is fine.)

       

      The key names in the table all have a hex number in parentheses next to them. This number is the physical keycode of the key on your keyboard (it can vary by model). If you need to change one Super_L to Super_R, first find the keycode you want to be associated to Super_R (aren’t sure which is the correct one? Run xev then tap the right Super a couple times. Somewhere in the maze of output is "keycode = 133″ (with a different number)).

       

      Run the xmodmap command

      xmodmap -e "keycode 133 = Super_R"

       

      to rename the key, then

      xmodmap -e "add mod4 = Super_R"

       

      To run those commands at startup : just put the commands in the file .xmodmap in your home directory

       

      xmodmap -e "remove mod4 = Super_L"
      xmodmap -e "add control = Super_L"

       

      Or put in ~/.xmodmap to activate on startup:

      remove mod4 = Super_L
      add control = Super_L

       

      NOTE : Ubuntu and derivatives no longer use xmodmap, but instead use xkb.

       

      xev et second xmodmap should be available in Ubuntu without extra installing them.

      Start terminal window and run xev. Now it’s active and waits for you to press a key. Then press the key whose behaviour you want to change. i.e. PgUp.

       

      xev will output some information about the pressed key. The third line is important. It should look similar to:

      state 0x10, keycode 110 (keysym 0xff55, Prior), same_screen YES,

       

      in this example Prior is the name of the behaviour the key is assigned to at the moment, the number keycode is the internal id to recognize the key. Now do this with another key i.e. PgDown give this output

      state 0x10, keycode 115 (keysym 0xff56, Next), same_screen YES,

       

      Here again the interesting part for us is keycode 115 and Next - the name of the behaviour.

       

      now when you want to swap the two keys use xmodmap.

      xmodmap -e "keycode 110 = Next"

       

      This changes the key with keycode 110 on your keyboard to the action Next. It’s pretty simple.

       

      Note that if the key you are mapping should have a different meaning when used with the Shift key (for example for British keyboard layouts, Shift+2 gives quotation marks) then you can simply list the secondary command after the first. For example if you want the key with code 53 to map to backslash normally, but to the bar symbol when used with shift, you might do:

      xmodmap -e "keycode 53 = backslash bar"

       

      Additional information: The sequence of these mappings depends on the keyboard layout. It usually is Key, Shift+Key, mode_switch+Key, mode_switch+Shift+Key, AltGr+Key, AltGr+Shift+Key, but can be very different for more special layouts, like in case of the German Neo 2 one. To skip a column use NoSymbol. Here is a comprehensive list of all keysyms.

      You can see the concrete sequence for your layout by finding it in one of the files in /usr/share/X11/xkb/symbols/.

       

      Note: These change are for the active X session only and will be lost after reboot. When you want to save the changes permanently you have to run the following commands after the ones above:

      xmodmap -pke >~/.Xmodmap

       

      Then you have to create a file named .xinitrc in your home directory where you put command xmodmap .Xmodmap in.

      You can now modify .Xmodmap and run xmodmap .Xmodmap from console to see the changes immediately. The changes in .Xmodmap will persist

      If the key you are remapping has different behavior depending on a state ( like how the keys in the numeric keyboard depend on NumLock) you simply have to do xmodmap -pm to get a list of modifiers and then do:

      xmodmap -e "KEYCODE MODIFIER = behaviour behaviour_with_modifier"

       

      Suppose, for example, that you want to get a period instead of a comma on the numeric keyboard (useful for most programmers), but you want to keep the "delete" behavior when NumLock is off.

      xmodmap -e "keycode 91 mod2 = KP_Delete period"

       

      mod2, because xmodmap -pm tells us that mod2 is Num_Lock, the other names are obtained by pressing the keys in xev.

       

      xev is not able to catch Fn key pressings

       

       

      If you’re trying to move a Shift key, there are a few extra steps:

      xmodmap -e "keycode 62 = Up" # Shift => Up
      xmodmap -e "keycode 111 = Shift_R" # Up => Shift
      xmodmap -e "add shift = Shift_R" # Make the new Shift key actually do shifting
      xmodmap -e "remove shift = Up" # Prevent the old Shift key from shifting
      xset r 62 # Make the new Up key autorepeat
      xset -r 111 # Prevent the new Shift key from autorepeating

       

      The most unix-y answer of all of those for a modifier (I had already done so way, way back with my iBook 2, when I wanted the enter key to have the function of Control_R, but had forgotten the details).

       

      An important answer for users using keyboards on Lenovo Laptops

       

      Since xmodmap is specifically programed to allow modifier key swappings, according to the man page, this should be doable atomically. – anon

       

       

      Trying to understand what’s happenning

       

      If I type xmodmap without argument (to get modifier list), I get:

      xmodmap:  up to 4 keys per modifier, (keycodes in parentheses):
      shift       Shift_L (0x32),  Shift_R (0x3e)
      lock        Caps_Lock (0x42)
      control     Control_L (0x25)
      mod1        Alt_L (0x40),  Meta_L (0xcd)
      mod2        Num_Lock (0x4d)
      mod3        ISO_Level5_Shift (0x69)
      mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
      mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

       

      The important part is for mod4. That’s where Super_L is.

       

      xmodmap -e "keycode 133 = Tab Super_L" && xmodmap | grep mod4
      mod4        Tab (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)

       

      The mod4 line changed and added Tab. That’s why your key 133 still open the window menu.

       

      By the way, I’m trying this on I3WM so the results can be a bit different.

      For example, if I press the key 133 on a terminal or text editor, it both write a tab and becomes a modifier.

      I also noticed I don’t have a different behavior with Shift because the type of the key is ONE_LEVEL.

      You can also run xev | grep key to see what happens with some key combinations.

      Solution

      But xmodmap also tells you can’t have more than 4 keys per modifier, so a solution (the only one that worked for me so far) is to sacrifice a key you don’t use / don’t have, make it become a Super_L.

       

      If you use QWERTY, you can modify the layout located on /usr/share/X11/xkb/symbols/us (it’s usually another file of the same folder if you’re using another layout), and write:

      key.type[Group1] = "TWO_LEVEL";
      key <MENU>{[Super_L]}; // ONE or TWO level, assuming MENU key isn't used
      key <LWIN>{[ Tab, Super_L]}; // should be TWO_LEVEL
      key.type[Group1] = "ONE_LEVEL";

       

      instead of (probably line 14 of the file)

      key <LWIN>{[Super_L]};

       

      Then, update your keyboard layout with setxkbmap us && xmodmap | grep mod4.

      You will get something like:

      mod4        Super_R (0x86),  Super_L (0x87),  Super_L (0xce),  Hyper_L (0xcf)

       

      If you still get Tab, you should probably sacrifice another key. Note that 0×85 is the hexadecimal value of 133, that mean this key will not be a direct mod4 but it still can behave like window key if Shift is pressed.

       

      Appreciate the detailed answer, I had totally given up on this! It’ll take me a few days before I have a chance to try this out, so I’m going to mark the answer as accepted for now, and if I have any additional feedback I’ll come back and comment here once I’ve played around with this a bit more.

       

      ok, no problem. Feedback are welcome and can help me to understand if the behavior is the same on another desktop. Do as you want. –

      ewen-goisot

       

       

 

Aucun commentaire

 

Laissez un commentaire