Fn key lock of Logitech keyboard

I have a Logitech G512 Carbon (wired usb keyboard) and I am sick of having to use the fn key to pause music or adjust the volume. On windows, I use logitech software to turn on fn lock so I can access media keys directly (without holding fn). Is there a way to do this on ubuntu? I haven't been able to find a solution for this.

EDIT:

Things I tried:

  • Solaar
  • Bunch of key combinations that are meant to activate fn lock. Looks like this keyboard does not support that

Solution 1:

I assume that currently function keys F1, F2,.....,F12 work without Fn and multimedia keys work with Fn and you want the opposite.

What you can do in this case is to remap function keys to work with Fn and multimedia keys to work without Fn by following these steps:

  1. Show the current keyboard map by running the following command in the terminal:
xmodmap -pke
  1. 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'.

  1. Inspect the output and identify lines that contain function keys names F1, F2, ...., F12 right after the = sign like so:
keycode  95 = F11 F11 F11 F11 F11 F11 XF86Switch_VT_11 F11 F11 XF86Switch_VT_11 F11 F11 F11 F11 XF86Switch_VT_11

The above line, for example, shows that the key with code number 95 is currently configured to trigger F11 function and you can change this behavior by assigning a different value to it like so xmodmap -e 'keycode 95 = New_Value'.

  1. Now switch the two keys' values by assigning the F11 functionality to key 232 and XF86MonBrightnessDown functionality to key 95 by running the following two commands in the terminal:

First,

xmodmap -e 'keycode 232 = F11'

Then,

xmodmap -e 'keycode 95 = XF86MonBrightnessDown'
  1. Do the same for all the multimedia and function keys to reflect what you see on your keyboard.

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

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

  1. Create and edit a script file in your home directory by running the following command in the terminal:
nano ~/.Modify_Multimedia_Keys.sh
  1. 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 95 = XF86MonBrightnessDown'
  1. Save the script file and exit the editor by pressing Ctrl + X then press Y.
  2. Make the script file executable by running the following command in the terminal:
chmod +x ~/.Modify_Multimedia_Keys.sh
  1. 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

Notice:

For more information and other ways of detecting or remapping keys, please refer to this answer.

Solution 2:

Have a look at the solaar package: apt install solaar solaar-gnome3. This package is designed for use mainly with Logitech wireless keyboards, but also supports some USB keyboards, sometimes with limited functionality.

If you have any success, please consider contributing here: https://pwr-solaar.github.io/Solaar/devices

If this doesn't work, consider building the latest version with the instructions here: https://pwr-solaar.github.io/Solaar/installation