[SOLVED] Keyboard mappings - use right ctrl key as Fn

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post please read how to get help
Post Reply
iain_33
Level 3
Level 3
Posts: 147
Joined: Sat Dec 22, 2018 11:29 am
Location: UK

[SOLVED] Keyboard mappings - use right ctrl key as Fn

Post by iain_33 »

On my new laptop's keyboard (which has Mint 19.3 Cinnamon), there's no dedicated home / end / page up / page down keys, instead I need to use the Fn key with the arrow keys (Fn+left/right = home/end, Fn+up/down = page up/down). The Fn key and the arrow keys are on opposite sides of the keyboard, which slows me down especially in text editors, when I'm editing scripts and the like.

I'm wondering if I can change the keyboard mappings so that the right ctrl key - which is right next to the arrow keys - acts as the Fn key - eg. right ctrl + left arrow = home, but leave the left ctrl key unaltered so I can still press eg. left ctrl + Fn + left arrow for ctrl & home (eg. go to top of the page in Firefox), or left ctrl + left arrow (eg. move the cursor back one word in a text editor).

The right ctrl key woudn't need to act as the Fn key across the board, just with the arrow keys.
Last edited by iain_33 on Mon Jun 08, 2020 6:37 pm, edited 1 time in total.
Linux Mint 19.3 Cinnamon on Lenovo Legion Y540 laptop (2020)
Linux Mint 19.3 Mate on HP G70 laptop (2009)
iain_33
Level 3
Level 3
Posts: 147
Joined: Sat Dec 22, 2018 11:29 am
Location: UK

Re: Keyboard mappings - use right ctrl key as Fn

Post by iain_33 »

Just thinking - even better than the right-ctrl key would be to remap the one to its left as the Fn key - I don't even know what this key does, when I press it I get what looks to be a touchpad appears on the screen, but I've disabled the touchpad in settings anyway. Then I can still use the right-ctrl key as is.

Image
Linux Mint 19.3 Cinnamon on Lenovo Legion Y540 laptop (2020)
Linux Mint 19.3 Mate on HP G70 laptop (2009)
iain_33
Level 3
Level 3
Posts: 147
Joined: Sat Dec 22, 2018 11:29 am
Location: UK

Re: Keyboard mappings - use right ctrl key as Fn

Post by iain_33 »

Right, some googling and playing about with xev | grep keycode tells me that keycode is 200, but it also detects 37 (left ctrl) and 50 (left shift) just from pressing that one key (the below output is just from pressing it once):

Code: Select all

iain@lenovo-y540:~$ xev | grep keycode
    state 0x10, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    state 0x14, keycode 50 (keysym 0xffe1, Shift_L), same_screen YES,
    state 0x15, keycode 200 (keysym 0x1008ffb0, XF86TouchpadOn), same_screen YES,
    state 0x15, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    state 0x11, keycode 50 (keysym 0xffe1, Shift_L), same_screen YES,
    state 0x10, keycode 200 (keysym 0x1008ffb0, XF86TouchpadOn), same_screen YES,
xev doesn't detect the Fn key at all.
Linux Mint 19.3 Cinnamon on Lenovo Legion Y540 laptop (2020)
Linux Mint 19.3 Mate on HP G70 laptop (2009)
magnus7
Level 4
Level 4
Posts: 251
Joined: Sat Jan 30, 2016 8:46 pm

Re: Keyboard mappings - use right ctrl key as Fn

Post by magnus7 »

Fn key can't be remapped because it is handled by BIOS.
Some Lenovo laptops have "Swap Fn and Ctrl" option in BIOS.
iain_33
Level 3
Level 3
Posts: 147
Joined: Sat Dec 22, 2018 11:29 am
Location: UK

Re: Keyboard mappings - use right ctrl key as Fn

Post by iain_33 »

Right, figured it out with xmodmap and some googling.

First I needed to define the right ctrl key as Mode_switch:

Code: Select all

xmodmap -e "keycode 105 = Mode_switch"
and then redefine the actions for the arrow keys:

Code: Select all

xmodmap -e "keycode 113 = Left NoSymbol Home"
xmodmap -e "keycode 114 = Right NoSymbol End"
xmodmap -e "keycode 111 = Up NoSymbol Prior"
xmodmap -e "keycode 116 = Down NoSymbol Next"
Now, the right ctrl key makes the arrow keys act as home / end / pg up / pg down, but they still act as the arrow keys with the left ctrl key.

Putting them all in a script and making it a startup application makes them stick.
Linux Mint 19.3 Cinnamon on Lenovo Legion Y540 laptop (2020)
Linux Mint 19.3 Mate on HP G70 laptop (2009)
iain_33
Level 3
Level 3
Posts: 147
Joined: Sat Dec 22, 2018 11:29 am
Location: UK

Re: [SOLVED] Keyboard mappings - use right ctrl key as Fn

Post by iain_33 »

The solution I found has been working fine for me - the xmodmap commands are in a script which I've put in my Startup Applications. But if I suspend my laptop, when I "wake up" again my xmodmap settings are gone. Is there some place I can put my script so it's run again on wakeup?

I've also found this happens if I do ctrl-alt-f1 to get a console, then ctrl-alt-f7 to get back to the GUI, my xmodmap settings are gone - but I'm not bothered about a solution for this since I rarely have to do it.
Linux Mint 19.3 Cinnamon on Lenovo Legion Y540 laptop (2020)
Linux Mint 19.3 Mate on HP G70 laptop (2009)
magnus7
Level 4
Level 4
Posts: 251
Joined: Sat Jan 30, 2016 8:46 pm

Re: [SOLVED] Keyboard mappings - use right ctrl key as Fn

Post by magnus7 »

Use xkb and the change will be permanent. Run this command in terminal and restart the computer. Any Shift key will make the arrow keys act as Home, End, Page Up, Page Down.

Code: Select all

sudo sed -i \
-e '83s|.*|key<UP>{[Up,Prior]};|' \
-e '84s|.*|key<LEFT>{[Left,Home]};|' \
-e '85s|.*|key<DOWN>{[Down,Next]};|' \
-e '86s|.*|key<RGHT>{[Right,End]};|' \
/usr/share/X11/xkb/symbols/pc \
&& sudo dpkg-reconfigure xkb-data
Post Reply

Return to “Other topics”