Skip to main content

Support for Logitech G910 GKeys on GNU/Linux

Project description

Logitech G910 keyboard gkey support for GNU/Linux (Project version: v0.3.0)

Because I didn't find any GKey support for Logitech G910 keyboard I decided to create this GKey mapper. Code is based on an issue in g910-gkey-uinput project. I expanded the code, so that it is more user-friendly to add functionality to GKeys.

Everything is described in great depth (and actually much better) on WIKI.

Requirements

To use this project you need:

  • Python >=3.7
  • uinput kernel module (more on this here)

Note:

From version 0.2.0 onwards the g810-led controller is no longer required because G-key to F-key mapping is disabled inside the driver.

Installation [AUR]

  • load uinput kernel module: modprobe uinput (on Manjaro is loaded by default afaik)
  • clone repo:
    git clone https://github.com/JSubelj/g910-gkey-macro-support.git
    
    or download & unzip:
    wget https://github.com/JSubelj/g910-gkey-macro-support/archive/refs/heads/master.zip; unzip master.zip
    
  • move to driver directory: cd g910-gkey-macro-support
  • run the installer script: chmod +x installer.sh; ./installer.sh
  • This will install the module, set a command g910-gkeys, add a service file to $HOME/.config/systemd/user/g910-gkeys.service or similar, install a default configuration file in $HOME/.config/g910-gkeys/config.json if none exists, and finally enable and start this service.

If you do not want to enable g910-gkeys automatically, use the -n switch: ./installer.sh -n. If you want to enable it later you can use: systemctl --user enable --now g910-gkeys.service. To just start the service till next reboot use: systemctl --user start g910-gkeys

Update

<= v0.3.0

If you use the installer your old config will be moved to the new location automatically. On manual installations you need to move your old config file to the new location and set the permissions to your username.

sudo mv /etc/g910-gkeys/config.json "$HOME"/.config/g910-gkeys/config.json
sudo chown "$USER":"$USER" "$HOME"/.config/g910-gkeys/config.json

You can delete the old log file sudo rm /var/log/g910-gkeys.log.

<= v0.2.4

If you update from version <= v0.2.4 you will need to make some manual changes to your /etc/g910-gkeys/config.json to make use of the new gkey profile feature. You don't need to do anything if you don't want to use the profile feature your old config will be loaded as default profile m1.

Uninstalling

By script (recommended)

Run the uninstalling script: chmod +x uninstall.sh; ./uninstall.sh
Run ./uninstall.sh -d to perform a dry-run (no actual removal will be done, actions will only be displayed).

Manual uninstall

If you prefer to do it manually, these are the commands :

  1. Disable and stop the service: systemctl --user disable --now g910-gkeys
  2. List pip packages that include g910-gkeys: pip (or pip3) list | grep g910-gkeys
  3. Remove the ones that concern this driver: pip (or pip3) uninstall ${pkgs to uninstall}
  4. Optional: Remove configuration directory rm -rf '$HOME/.config/g910-gkeys
    If you want to reinstall the driver again later consider keeping the config file.

Configuration

Configuration should be located in /home/[username]/.config/g910-gkeys/config.json and should be syntactically correct. Example configuration can be found in docs folder: ex_config.

Supported languages:

  • "de" - german
  • "en" - english (default)
  • "fr" - french
  • "si" - slovenian

Even if your language is not supported you can still use the driver with hotkey_type run. Other types won't work as expected with the wrong language configured.

Hotkey types

The mapper supports five types of hotkeys (also described in hotkey_types.txt):

  • "typeout" - Type out (ex. clicking on GKey types out a string)
  • "shortcut" - Shortcuts (ex. clicking on GKey presses shift+f4)
  • "run" - Starting a program (anything you can start from shell)
  • "python" - Execute a snippet of Python code and print provided output (see ex. below)
  • "uinput" - Direct mapping with uinput.KEY_XY
  • "nothing" - Do nothing (unbound key)

To add a hotkey add to config.json the following code:

"g<no_of_gkey>": {
    "hotkey_type": <type of command "nothing" or "typeout" or "shortcut" or "run">,
    "do": "<thing to do>"
}

Depending on the hotkey command, the syntax for "do" is different (supported characters for typeout and hotkeys are listed in supported_keys.txt):

  • "typeout" - Type out syntax is same as you would type text out (ex. "tyPe Me Out!")
  • "shortcut" - Shortcuts are separated by a plus sign and a comma (ex. "ctrl+c,ctrl+v")
  • "nothing" - If hotkey_type is set to "nothing" then "do" key need not exist or can be anything.
  • "run" - Run has the same syntax as you would type a cli program in command line (ex. "systemctl daemon-reload")
  • "python" - A Python one-line script. If output is desired, the script should define a global variable named output_string and set it to the string to be output.
  • "uinput" - A key defined by python3-uinput to emit (ex. KEY_F13 or KEY_KATAKANA)

Important: Commands and python code is executed as root

Profiles

There are four profiles you can use and set up different gkey macros in config. Select the profile with M[1-3|R] key on your keyboard. If you use the profile feature you can also use the following parameter:

  • notify - Send notifications if profile gets changed
  • profiles - Define a profile which is bound to the matching mkey

The following example shows how to set slovenian layout and define the g1-5 macro keys for profile m1 and m2 and shows an example of every hotkey_type.

{
   "notify": "True",
   "keyboard_mapping": "si",
   "profiles": {
       "MEMORY_1": {
           "MACRO_1": {
               "hotkey_type": "uinput",
               "do": "KEY_F13"
           },
           "MACRO_2": {
               "hotkey_type": "shortcut",
               "do": "ctrl+c"
           },
           "MACOR_3": {
               "hotkey_type": "typeout",
               "do": "averylongemailadressyoudontwanttowriteoutyourself@gmail.com"
           },
           "MACRO_4": {
               "hotkey_type": "run",
               "do": "/path/to/bash/script"
           },
           "MACRO_5": {
               "hotkey_type": "python",
               "do": "import datetime; global output_string; output_string = datetime.now().strftime('%Y-%m-%d %H:%M:%S')"
           }
       },
       "MEMORY_2": {
           "MACRO_1": {
               "hotkey_type": "uinput",
               "do": "KEY_KATAKANA"
           },
           "MACRO_2": {
               "hotkey_type": "shortcut",
               "do": "ctrl+v"
           },
           "MACRO_3": {
               "hotkey_type": "typeout",
               "do": "ssh -p1234 -i ~/.ssh/id_rsa user@domain\n"
           },
           "MACRO_4": {
               "hotkey_type": "run",
               "do": "DISPLAY=:0 nohup firefox & 2>&1 > /dev/null"
           },
           "MACRO_5": {
               "hotkey_type": "python",
               "do": "import datetime; global output_string; output_string = datetime.datetime.now().isoformat()"
           }
       }
   }
}

The DISPLAY variable defines the screen to open the app on a multi-screen-setup.

Troubleshooting

To see a log of the running service use:

journalctl --user --user-unit=g910-gkeys

The code is tested on Logitech G910 keyboard with

  • OS: Ubuntu 20.04.6 LTS, Linux 5.4.0-159-generic, GNOME: 3.36.9

Disclaimer

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

g910-gkeys-0.4.0.tar.gz (63.9 kB view details)

Uploaded Source

Built Distribution

g910_gkeys-0.4.0-py3-none-any.whl (53.0 kB view details)

Uploaded Python 3

File details

Details for the file g910-gkeys-0.4.0.tar.gz.

File metadata

  • Download URL: g910-gkeys-0.4.0.tar.gz
  • Upload date:
  • Size: 63.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for g910-gkeys-0.4.0.tar.gz
Algorithm Hash digest
SHA256 113ddf45f2d88cd2d9cde7812410e74348323aa8befdedb73234681ee9a84dbc
MD5 fbcb22b6032a174a60108883b77906ba
BLAKE2b-256 6100548d0b5c0f427659eb0b03df8efe13775d15e1cce903a78e6f27ce170447

See more details on using hashes here.

File details

Details for the file g910_gkeys-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: g910_gkeys-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 53.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for g910_gkeys-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e6046c6d6628c4f136282c885533933ccdb69cf76badea7e352e3ab1455436eb
MD5 a141d1bbdddba8ea4a3dfa81218e5c8c
BLAKE2b-256 1cd154b5101175abd48fc69fddcbb748fca7ac3367a4e19ecbe3b26bae4276d6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page