Ask Your Question
0

How to assign ctrl + up to home, ctrl + down to end, ctrl + left to page up and ctrl + right to page down?

asked 2015-07-29 07:35:20 -0500

James Fu gravatar image

I am running Fedora 22 on the Toshiba Chromebook 2, which is missing some keys such as Home, End, Pg Up and Pg Dn. I would like to map them to Ctrl+, , and respectively.

As far as my research goes, there is no good way to remap them in xmodmap and that the only way is to first remap Ctrl to mode_switch, but I would then lose the use of the key as Ctrl, i.e. Ctrl+C will no longer copy.

So is there a better way to do this in xmodmap? And if not, is there another program that could do this?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2015-07-29 10:29:15 -0500

BRPocock gravatar image

updated 2015-08-06 13:20:15 -0500

xmodmap is deprecated; it would work, but it'll interact badly with other programs. (For example, you'll lose changes every time you switch consoles, or lock the screen, or your notebook goes to sleep, or …)

The “modern” tool for this purpose is the xkb extension, which is really powerful, and unfortunately, really complex.

For your purposes, you could create a small “patch” to the xkb files for your keyboard layout. You didn't specify, but I'm going to guess that you have the us layout (QWERTY, with an Alt but no AltGr key, and the number keys shifted give you ! @ # $ % ^ & ( )).

The X11 names for the “Page Up/Down” keys are actually Prior and Next, and Home and End have the same names.

What you'll want to do is add a Variant layout to the xkb definitions, which will make a few alterations.

First, make a file you can write to.

sudo touch /usr/share/X11/xkb/symbols/jfu
sudo chown $USER /usr/share/X11/xkb/symbols/jfu

Looking at the base layout in /usr/share/X11/xkb/symbols/pc, the keyboard keys that you want to remap seem to have the keycodes of: <UP> <DOWN> <LEFT> <RGHT> (no “i” in “right”)

Open the file in your favorite editor (/usr/share/X11/xkb/symbols/jfu) and add:

default partial modifier_keys 
xkb_symbols "jfu" {
   name[Group1]="US";
   key <UP> { 
    type= "PC_CONTROL_LEVEL2",
    symbols[Group1]= [ Up, Prior ] };
   key <DOWN> { 
    type= "PC_CONTROL_LEVEL2",
    symbols[Group1]= [ Down, Next ] };
   key <LEFT> {
    type= "PC_CONTROL_LEVEL2",
    symbols[Group1]=  [ Left, Home ] };
   key <RGHT> { 
    type= "PC_CONTROL_LEVEL2",
    symbols[Group1]= [ Right, End ] };
 };

This will override those specific keys. PC_CONTROL_LEVEL2 means that the second key symbol (e.g. Prior) is reached by Control, rather than Shift. (aA changes by Shift, for example.)

Now that you have such a definition, you can test engaging it from a Terminal. Make sure you have the tools:

 rpm -q xorg-x11-xkb-utils || sudo dnf -y install xorg-x11-xkb-utils

Then check you current settings:

 setxkbmap -v

Yours will probably be something quite different than mine, as I use a custom keyboard called a “Spacey Cadet” layout, but mine says:

Trying to build keymap using the following components: 
keycodes:  evdev+aliases(qwerty) 
types:     complete+spacey 
compat:    complete+spacey 
symbols:   pc+spacey+inet(evdev) 
geometry:  pc(pc105)

I expect your ’symbols’ to be more like pc+us+inet(evdev) or something.

For safety: Open a second terminal, and type in (but do not yet press Return) ’setxkbmap us’. If you mess up your layout horribly, you can press ’Return’ in that window to recover to at least a somewhat usable state.

We want to load the symbols variant you just created, so carefully copy the existing symbols into a command like this. (The ’-v’ is so you can watch it work.)

 setxkbmap -v -symbols 'pc+us+inet(evdev)+jfu'

Hopefully, that works and you can try out your new key mappings. But it'll be reset whenever the system rechecks your keyboard (eg, after logging out or sleep). So, let's add it ... (more)

edit flag offensive delete link more

Comments

Hey Pocock, thanks much for the very detailed answer! It was very helpful to me. Since I'm apparently too green to upvote or edit your answer, let me point out a few issues I ran into:

  • The syntax for the symbols file requires a semi-colon at the end of each line, and threw an error without when I tried to run setxkbmap -v -symbols 'pc+us+inet(evdev)+jfu'.
  • While the English (James Fu Chromebook) option showed after editing evdev.xml, the key combinations did not work. After comparing to the Dvorak variant, I noticed its config was in the main /usr/share/X11/xkb/symbols/us file
James Fu gravatar imageJames Fu ( 2015-08-03 03:48:24 -0500 )edit
  • (continued) as opposed to in a file of its own. Out of laziness, instead of experimenting further, I've just added the directives to the main xkb_symbols "basic" block and that preserves across reboots just fine. (Though I know I may possibly have to redo this step if an update / upgrade overwrites this file.)
  • At this point I'm just being pedantic, but there's a double opening <variant> tag in your proposed amendment to /usr/share/X11/xkb/rules/evdev.xml. And I also thought editing as root was better than claiming ownership of those shared files, though I could be wrong. :)
James Fu gravatar imageJames Fu ( 2015-08-03 03:55:59 -0500 )edit

+1 on all those points. Personally, I never edit anything as root, and chowning these files helps remind me that they're “my fault,” but whatever works for you. Sorry about the misc cut-and-paste errors there :-( I'll try to edit the post.

BRPocock gravatar imageBRPocock ( 2015-08-06 13:17:29 -0500 )edit

This works for me for the left->home and right->end cases, but doesn't work for the up->pageup down->pagedown cases. It seems like ctrl-up and ctrl-down already have some behaviour mapped like scrolling to the top or bottom of the page (i.e. not just going up or down by one page, but to the beginning or end), and this behaviour is not being overridden. Any ideas on how to either remove the old behaviour or make sure that the new definition takes precedences? Or could it be a problem with various applications having higher-level behaviour defined for those keypresses?

kurros gravatar imagekurros ( 2016-04-27 09:22:37 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2015-07-29 07:35:20 -0500

Seen: 1,210 times

Last updated: Aug 06 '15