23

I'd like to add set a functionality to the pair fn+right/left to be like in Mac - 'home' and 'end'. I don't mean to replace the 'home' and 'end' buttons - just adding another 'home'/'end' keys. The advantage is in writing/modifying text. I use the arrows a lot, and I also use the home and end buttons, but why jump to a whole new button? My left hand is already near the fn (function) key - ready to press control or shift.

How do I set this?

Thanks.

2 Answers 2

9

I definitely understand why you want to do this! Here's my bet what I have done:

Launch a terminal and run 'xev'. Place your mouse cursor over the Event Tester window and press fn+right/left. You should get a read-out like:

    KeyRelease event, serial 36, synthetic NO, window 0x5200001,
root 0xb2, subw 0x0, time 89989888, (98,124), root:(1007,175),
state 0x0, keycode 171 (keysym 0x1008ff17, XF86AudioNext), same_screen YES,
XLookupString gives 0 bytes: 
XFilterEvent returns: False

This is for my keyboard and fn+right. Find the keycode -- here it's 171.

Now go edit your .bashrc file in your home directory. It's hidden, so pres Ctrl+H in Nautilus to show. Then add lines

    xmodmap -e "keycode 171 = Home"
    xmodmap -e "keycode xxx = End"

where you replace the 171 and xxx with the obtained keycodes. Then save and close the file. Close all your terminals, open one, and you should be ready to go!

Now, there is one draw-back: you have to activate this on every boot. You do that by opening a terminal, and that's it. You can close it again immediately. Or you can try fixing it to do it automatically, as described here. I just run the terminal using a shortcut and then kill it...

12
  • 5
    The keycode for fn+right is the same as just pressing right (without fn). This is problematic, because I don't want to override my right/left key. Sep 27, 2011 at 11:26
  • Well, then it may not be a "function key" (or what the correct term is). My arrows are, but they are also media keys. Then I don't know what to do, sorry.
    – Rasmus
    Oct 15, 2011 at 16:31
  • 1
    Event tester responds one key at a time. I don't understand how did you manage to get the code for pressing the two together. Mar 1, 2018 at 19:33
  • 2
    I cannot see any key output when clicking FN + arrow key. Does that mean that it's not possible to bind there anything ?
    – Jurosh
    Apr 17, 2019 at 13:13
  • 3
    Just like @Jurosh I don't see any output when doing fn+leftarrow either (I'm on an XPS13). Do you have any idea whether that makes it impossible to bind home to fn+leftarrow?
    – kramer65
    Jul 7, 2019 at 11:52
0

If you have Ubuntu+Gnome and xev does not show anything when you type Fn+Left or Fn+Right - than you might have an interceptor in Gnome session like I did. Also my hardware laptop keyboard shows "backward" and "forward" player/music icons for left and right buttons - it means my hardware keyboard sends keycode 173 for Fn+Left and keycode 171 for Fn+Right.

Disable gnome session listeners

You can disable listeners with UI dconf-editor.

Install and run dconf-editor.

Go to the following paths and disable Use default value and put empty array [] in Custom value.

For Fn+Left:

/org/gnome/settings-daemon/plugins/media-keys/previous-static.

For Fn+Right:

/org/gnome/settings-daemon/plugins/media-keys/next-static

Apply changes for both paths and close dconf-editor.

Apply software buttons mapping with xmodmap

Now apply custom handler for Fn+Left:

xmodmap -e "keycode 171 = End"

Before this setting it was for me xmodmap -pk | grep -i '171':

171     0x1008ff17 (XF86AudioNext)  0x0000 (NoSymbol)   0x1008ff17 (XF86AudioNext)  0x0000 (NoSymbol)   0x1008ff17 (XF86AudioNext)

After this setting:

171     0xff57 (End)    0x0000 (NoSymbol)   0xff57 (End)    0x0000 (NoSymbol)   0xff57 (End)

Apply custom handler for Fn+Right:

xmodmap -e "keycode 173 = Home"

Before xmodmap -pk | grep -i '173':

173     0x1008ff16 (XF86AudioPrev)  0x0000 (NoSymbol)   0x1008ff16 (XF86AudioPrev)  0x0000 (NoSymbol)   0x1008ff16 (XF86AudioPrev)

After:

173     0xff50 (Home)   0x0000 (NoSymbol)   0xff50 (Home)   0x0000 (NoSymbol)   0xff50 (Home)

Now it works for me. However the result is not permanent, after reboot you have to do this again. Some startups scripts to do this do not work nice, because xmodmap must be initialized only after some time (when it is ready).

Apply software buttons mapping with xkb

Turns out that xmodmap is outdated and not used anymore in Gnome.

Permanent solution is to use xkb.

Create symbol file fn_mod at /usr/share/X11/xkb/symbols/ (sudo requires) with following content:

// /usr/share/X11/xkb/symbols/inet
// key <I171>   {      [ XF86AudioNext         ]       };
// key <I173>   {      [ XF86AudioPrev         ]       };
//
// /usr/share/X11/xkb/symbols/pc
// key <HOME> { [  Home         ]   };
// key  <END> { [  End          ]   };
//
// make Fn+Left (keycode 171) act as Home
partial modifier_keys
xkb_symbols "left_as_home" {
    key <I171> { [ End ] };
};

// make Fn+Right (keycode 173) act as End
partial modifier_keys
xkb_symbols "right_as_end" {
    key <I173> { [ Home ] };
};

Make backup for following files in case you will brake them:

/usr/share/X11/xkb/rules/evdev.xml
/usr/share/X11/xkb/rules/evdev
/usr/share/X11/xkb/rules/evdev.lst

Add following content into evdev.xml (<xkbConfigRegistry> -> <optionList> ->):

    <group allowMultipleSelection="true">
      <configItem>
        <name>fn_mod</name>
        <description>Fn key behavior</description>
      </configItem>
      <option>
        <configItem>
          <name>fn_mod:left_as_home</name>
          <description>Fn+Left (aka XF86AudioPrev) act as Home</description>
        </configItem>
      </option>
      <option>
        <configItem>
          <name>fn_mod:right_as_end</name>
          <description>Fn+Right (aka XF86AudioNext) act as End</description>
        </configItem>
      </option>
    </group>

Add following content into evdev (Find line ! option = symbols and append on the next line):

  fn_mod:left_as_home  = +fn_mod(left_as_home)
  fn_mod:right_as_end  = +fn_mod(right_as_end)

Add following content into evdev.lst (Find line ! option and append on the next line):

  fn_mod               Fn key behavior
  fn_mod:left_as_home  Fn+Left (aka XF86AudioPrev) act as Home
  fn_mod:right_as_end  Fn+Right (aka XF86AudioNext) act as End

evdev.xml changes will create UI tweak in gnome-tweaks. To check/enable this open gnome-tweaks go to the Keyboard & Mouse -> Additional Layout Options -> Fn key behavior.

Finally reboot the session and check in terminal.

$ setxkbmap -query
rules:      evdev
model:      pc105
layout:     us,ru,us
variant:    ,,
options:    fn_mod:left_as_home,fn_mod:right_as_end
$ setxkbmap -print
xkb_keymap {
    xkb_keycodes  { include "evdev+aliases(qwerty)" };
    xkb_types     { include "complete"  };
    xkb_compat    { include "complete"  };
    xkb_symbols   { include "pc+us+ru:2+us:3+inet(evdev)+fn_mod(left_as_home)+fn_mod(right_as_end)" };
    xkb_geometry  { include "pc(pc105)" };
};
4
  • I was afraid of doing such a long workaround. But seriously, it worked flawlessly. Thank you so much. This decision on Dell XPS 9500/9300 is so DUMB. Seriously. they JUST removed these shortcuts. It looks like they don't want to sell these 9500/9300 for developers and power users. Anyways. Thank you.
    – leoheck
    Mar 29, 2021 at 23:03
  • I was too fast commenting here. It actually does not help too much since it does not enable by default all combinations of Fn+Arrow, with Ctrl, Shift for instancece
    – leoheck
    Mar 29, 2021 at 23:10
  • 1
    @leoheck did you managed to make it work for XPS 9500? Home/End still don't want to budge for me
    – Fuxi
    Jun 8, 2021 at 23:08
  • 1
    No, unfortunately I dropped this. Seriously, DELL is doing the worst on these XPS computers. Why the hell they have disable one of its best features?
    – leoheck
    Oct 6, 2021 at 14:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .