set fn + arrow to represent 'home' and 'end'

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.


Solution 1:

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...