4

I have a Logitech G512 Carbon (wired USB keyboard) and am sick of using the FN key to pause music or adjust the volume. I use Logitech software on Windows to turn on the fn lock to 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
Michael
  • 63
  • Does [Fn]+[Esc] not put the keyboard into Fn Lock mode? This works on every Logitech keyboard I've used in the past, though I'll admit to never having used any of the G-series. –  Feb 05 '21 at 02:43
  • I tried already, it doesn't work :( – Michael Feb 05 '21 at 04:54
  • You can remap the function keys and do the opposite of this solution using the tools and methods explained in the same linked answer. – Raffa Feb 05 '21 at 15:07
  • If you still need help with that, please add a clear picture of the multimedia keys on your keyboard and the output of xmodmap -pke to your question. – Raffa Feb 05 '21 at 15:55
  • I would rather not lose my function keys. This is a hacky way. I guess I will have to do something like this if I cannot find another way. – Michael Feb 05 '21 at 18:11
  • You shouldn't loose them. You should remap them to work with Fn. I assume that currently F1, F2,.....,F12 work without Fn and multimedia keys work with Fn and you want the opposite. Right? – Raffa Feb 05 '21 at 18:52
  • Ahh I see. I will try this out and let you know – Michael Feb 05 '21 at 19:21
  • 1
    @Raffa Please write this solution as an answer so you can have the bounty :) – Michael Feb 05 '21 at 20:14
  • I am glad it worked. I wish I had the chance to help you more although you are so smart you made it work with minimal help. OK I will write an answer for posterity and explain the best way I can. – Raffa Feb 05 '21 at 20:23

2 Answers2

5

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

It has a function to swap the Fx keys:

enter image description here

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

lanoxx
  • 1,229
ThankYee
  • 1,708
  • 1
    I tried solaar already. My keyboard is not recognized. – Michael Feb 05 '21 at 18:09
  • 1
    Worked for mew with a K400, thanks – Paul Ridgway Jan 02 '22 at 10:12
  • This seems like a super useful app, I updated the comment to also added a screenshot of the relevant feature to swap Fx keys. However, on Ubuntu 22.04 with my MX Keys it somehow did not have any effect and the function keys still trigger the media key action instead of the function number. – lanoxx Nov 19 '23 at 11:31
  • 1
    thanks! It works for my K380 under Ubuntu 22.04 – Alexey Nov 22 '23 at 09:31
4

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.

Raffa
  • 32,237