Adjusting keyboard layout in GNOME desktop to get backslash key!

Posted on 2014-03-07
Last Modified: 2014-03-24
Ah hello.

I have a keyboard that is identical to this key-layout wise.  I normally run Windows, but am currently using an Oracle Linux virtual machine (running in VirtualBox) using GNOME desktop.

Now, for some reason in Linux, pressing the key to the left of Z (with | and \ on it) displays a '<'.  With the shift key down, it displays a '>': in Windows it displays a \ and | respectively.  To get a \ and |, I have to press the key to the left of Enter on the third row (that with # and ~ on it).

This is highly annoying!

I don't know a lot about GNOME and Linux in general, but have found the Keyboard preferences dialog.  It doesn't seem to give me the option to change a certain key's behaviour however.

Can someone please tell me how to force Linux to treat my keyboard in the same way Windows does?

Question by:mrwad99
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 8
  • 7
  • +1
LVL 27

Expert Comment

ID: 39912397
you configured a regular qwerty layout while you're using a different one. do not try to map specific keys, you need to find what is the proper layout.

most dists will do this properly at install time, xorg-configure should be helpful after install if you're running X, as far as i know, gnome does not have an autodetect feature any more but your specific linux flavor may have. what is it ?

also, please note that it is possible that vmware emulates the wrong type of keyboard. this is espetially possible if you're using the vmware direct console access (non graphic) with the wrong type of terminal (i'd guess you need vt100). this seems like a likely option to me because backspace probably should work with the wrong layout
LVL 19

Author Comment

ID: 39912429
Thanks for responding!

My "flavour" is Oracle Enterprise Linux.  I am not running VMWare; I use VirtualBox.  I checked the keyboard on my Windows virtual machines and they respond to the correct backslash key, so it seems to be a Linux specific problem.

I tried running xorg-configure from a bash shell but it is an unknown command...

How can I proceed?
LVL 62

Expert Comment

ID: 39913204
You have UK english keyboard.
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

LVL 19

Author Comment

ID: 39913238
That is interesting.  I don't have the UK English keyboard layout (although I am in the UK), I have the US keyboard layout, since I learned to touch-type using an American piece of software which insisted I have US keyboard layout.  This means that shift-2 produces a @ instead of ", and the @ sign now gives me " (as per the keyboard layout on the image above).

Changing Linux back to use the UK English keyboard gives me back the correct | and \ behaviour, however I now have to use shift-2 for a double quote.  This will become equally annoying very quickly.

My Windows 7 (host) machine has US keyboard layout and the correct |\ behaviour, but Linux does not want to play ball.

Surely there is something I can do to fix this?!
LVL 62

Expert Comment

ID: 39913280
"dpkg-reconfigure keyboard-configuration"
"dpkh-reconfigure console-setup"
edit /etc/defaults/keyboard
are you sure you have gnome and not unity?
LVL 19

Author Comment

ID: 39913311
Yes, I have the GNOME desktop; here is a screenshot of my taskbar to prove this:

I entered those commands at a bash shell but got "command not found" for each of them.

LVL 27

Expert Comment

ID: 39913439
my bad : virtualbox does not mess with your keyboard

the command is xorg -configure with a space before "-"

dpkg-something are commands for the debian system family. i assume oracle to be redhat/centos based

your keyboard is called english(united kingdom) on my current machine. it is available in the layouts list

the command "setxkbmap gb" should switch to the proper layout on any OS running the xwindows system
LVL 62

Assisted Solution

gheist earned 166 total points
ID: 39913644
Ahh it is oracle Linux, i thought it is ubuntu :S

system-config-keyboard changes all keyboard layouts in a snap (if ran as root)
Actually when you select us keyboard
/etc/sysconfig/keyboard has following:
/etc/yum.conf boot command line is not changed by that:
KEYBOARDTYPE=pc LAYOUT=us (or none of them)

In gnome Something like Options/Preferences/System in whichever order, then keyboard, then layout tab.

  install missing software with e.g
yum install system-config-keyboard
LVL 27

Expert Comment

ID: 39913789
in gnome the layouts are available in "system parameters"/"countries and languages"/"input methods"

there is also a link in the "keyboard" snippet

click on the small "+" sign, add the english(united kingdom) keyboard and remove all other keyboards once you confirmed it is the proper one


changing /etc/sysconfig/keyboard, or xorg.conf may also work. i'm unsure if gnome will give priority to it's own settings.


setxkbmap should always work but will only last until you logout. it is not unreasonable to add this command to startx or have the display manager run it when you logon or when it starts
LVL 19

Author Comment

ID: 39914904
OK this is getting silly now.

Both, please see the attached image for a reminder of what I am after.


1) xorg -configure gives me "command not found".
2) I found the keyboard preferences dialog, and can see how to change from English US and English UK, but they still don't give me the exact combination I get with Windows 7.

I ran setxkbmap gb and it did indeed give me the UK keyboard layout.  But then I have to press shift-2 to get a double quote, instead of shift @.


I ran system-config-keyboard, but it seems that I still cannot get the correct combination of keys that I get on Windows, see attached image.

Are there any utilities or any low level tweaking I can use?  I find it hard to see Why is this so dificult; Windows manages it so why can't the (supposedly much better) Linux OS do the same?  Perhaps Windows has just managed it by fluke...
LVL 27

Expert Comment

ID: 39915017
I ran setxkbmap gb and it did indeed give me the UK keyboard layout.  But then I have to press shift-2 to get a double quote, instead of shift @.

meaning you're using a variant of the gb keyboard. probably the "gb extended"

Are there any utilities or any low level tweaking I can use?  I find it hard to see Why is this so dificult; Windows manages it so why can't the (supposedly much better) Linux OS do the same?  Perhaps Windows has just managed it by fluke...

dunno about windows but there is a dumb tool in most linuxes that will ask you to type for variou keys and detect the keyboard accordingly. unfortunately it is usually only available at install time

xorg -configure gives me "command not found".

my bad the command is "Xorg" and not "xorg"
LVL 62

Expert Comment

ID: 39915238
It is hard to guess what you want
Shift-2 means @ in US keyboard or " in UK one

Actually you can type X -configure
LVL 19

Author Comment

ID: 39915738
It is hard to guess what you want

I have stated clearly above on my diagram what I want :)
LVL 29

Expert Comment

ID: 39916382
In the past, I've used xmodmap to remap the keyboard layout in gnome and the terminal.

But it seems that the newer versions of gnome have issues with it now and you may need to work around it.
LVL 19

Author Comment

ID: 39917095
Thanks serialband, I shall investigate these links and come back tomorrow.
LVL 29

Assisted Solution

serialband earned 167 total points
ID: 39918361
Here's the keymap for the standard US qwerty keyboard layout.  I also have the dovrak layout.  You should be able to switch the keycodes for your UK keyboard layout.

keycode   8 = Escape
keycode   9 = 1 exclam
keycode  10 = 2 at
keycode  11 = 3 numbersign
keycode  12 = 4 dollar
keycode  13 = 5 percent
keycode  14 = 6 asciicircum
keycode  15 = 7 ampersand
keycode  16 = 8 asterisk
keycode  17 = 9 parenleft
keycode  18 = 0 parenright
keycode  19 = minus underscore
keycode  20 = equal plus
keycode  21 = BackSpace Delete
keycode  22 = Tab KP_Tab
keycode  23 = Q
keycode  24 = W
keycode  25 = E
keycode  26 = R
keycode  27 = T
keycode  28 = Y
keycode  29 = U
keycode  30 = I
keycode  31 = O
keycode  32 = P
keycode  33 = bracketleft braceleft
keycode  34 = bracketright braceright
keycode  35 = Return
keycode  36 = Control_L
keycode  37 = A
keycode  38 = S
keycode  39 = D
keycode  40 = F
keycode  41 = G
keycode  42 = H
keycode  43 = J
keycode  44 = K
keycode  45 = L
keycode  46 = semicolon colon
keycode  47 = apostrophe quotedbl
keycode  48 = grave asciitilde
keycode  49 = Shift_L
keycode  50 = backslash bar
keycode  51 = Z
keycode  52 = X
keycode  53 = C
keycode  54 = V
keycode  55 = B
keycode  56 = N
keycode  57 = M
keycode  58 = comma less
keycode  59 = period greater
keycode  60 = slash question
keycode  61 = Shift_R
keycode  62 = KP_Multiply
keycode  63 = Alt_L Meta_L
keycode  64 = space
keycode  65 = Caps_Lock
keycode  66 = F1
keycode  67 = F2
keycode  68 = F3
keycode  69 = F4
keycode  70 = F5
keycode  71 = F6
keycode  72 = F7
keycode  73 = F8
keycode  74 = F9
keycode  75 = F10
keycode  76 = Pause
keycode  77 = Scroll_Lock
keycode  78 = Home KP_7
keycode  79 = Up KP_8
keycode  80 = Prior KP_9
keycode  81 = KP_Subtract
keycode  82 = Left KP_4
keycode  83 = KP_Space KP_5
keycode  84 = Right KP_6
keycode  85 = KP_Add
keycode  86 = End KP_1
keycode  87 = Down KP_2
keycode  88 = Next KP_3
keycode  89 = Insert KP_0
keycode  90 = Delete KP_Decimal
keycode  91 = F11
keycode  92 = F12
keycode  93 = KP_Enter
keycode  94 = Control_R
keycode  95 = KP_Divide
keycode  96 = Alt_R Meta_R
keycode  97 = Num_Lock
keycode  98 = Home
keycode  99 = Up
keycode 100 = Prior
keycode 101 = Left
keycode 102 = Right
keycode 103 = End
keycode 104 = Down
keycode 105 = Next
keycode 106 = Insert
keycode 107 = Delete
keycode 108 = KP_0
keycode 109 = KP_1
keycode 110 = KP_2
keycode 111 = KP_3
keycode 112 = KP_4
keycode 113 = KP_5
keycode 114 = KP_6
keycode 115 = KP_7
keycode 116 = KP_8
keycode 117 = KP_9
keycode 118 = KP_Decimal
keycode 119 =
keycode 120 =
keycode 121 =
keycode 122 =
keycode 123 =
keycode 124 =
keycode 125 =
keycode 126 =
keycode 127 =
keycode 128 =
keycode 129 =
keycode 130 =
keycode 131 =
keycode 132 =
keycode 133 =
keycode 134 =
keycode 135 =
keycode 136 =
keycode 137 =
keycode 138 =
keycode 139 =
keycode 140 =
keycode 141 =
keycode 142 =
keycode 143 =
keycode 144 =
keycode 145 =
keycode 146 =
keycode 147 =
keycode 148 =
keycode 149 =
keycode 150 =
keycode 151 =
keycode 152 =
keycode 153 =
keycode 154 =
keycode 155 =
keycode 156 =
keycode 157 =
keycode 158 =
keycode 159 =
keycode 160 =
keycode 161 =
keycode 162 =
keycode 163 =
keycode 164 =
keycode 165 =
keycode 166 =
keycode 167 =
keycode 168 =
keycode 169 =
keycode 170 =
keycode 171 =
keycode 172 =
keycode 173 =
keycode 174 =
keycode 175 =
keycode 176 =
keycode 177 =
keycode 178 =
keycode 179 =
keycode 180 =
keycode 181 =
keycode 182 =
keycode 183 =
keycode 184 =
keycode 185 =
keycode 186 =
keycode 187 =
keycode 188 =
keycode 189 =
keycode 190 =
keycode 191 =
keycode 192 =
keycode 193 =
keycode 194 =
keycode 195 =
keycode 196 =
keycode 197 =
keycode 198 =
keycode 199 =
keycode 200 =
keycode 201 =
keycode 202 =
keycode 203 =
keycode 204 =
keycode 205 =
keycode 206 =
keycode 207 =
keycode 208 =
keycode 209 =
keycode 210 =
keycode 211 =
keycode 212 =
keycode 213 =
keycode 214 =
keycode 215 =
keycode 216 =
keycode 217 =
keycode 218 =
keycode 219 =
keycode 220 =
keycode 221 =
keycode 222 =
keycode 223 =
keycode 224 =
keycode 225 =
keycode 226 =
keycode 227 =
keycode 228 =
keycode 229 =
keycode 230 =
keycode 231 =
keycode 232 =
keycode 233 =
keycode 234 =
keycode 235 =
keycode 236 =
keycode 237 =
keycode 238 =
keycode 239 =
keycode 240 =
keycode 241 =
keycode 242 =
keycode 243 =
keycode 244 =
keycode 245 =
keycode 246 =
keycode 247 =
keycode 248 =
keycode 249 =
keycode 250 =
keycode 251 =
keycode 252 =
keycode 253 =
keycode 254 =

Open in new window

LVL 27

Expert Comment

ID: 39918740
there is definitely a keyboard version that corresponds to your keyboard.

you can try the ones you have not tried yet from the interface. have you tried the "gb extended" like i suggested above ?

or you can stick "setxkbmap gb" in your session startup if it does the trick
you can run "gnome-session-properties" from a terminal to add new startup programs or you can also add it in various other places such as in the display manager's startup so it is already launched when you get to the password prompt
LVL 62

Expert Comment

ID: 39918753
His picture shows 100% standard UK keyboard with allsmalls instead of ALLCAPS printed for letters. (Who else would ever need Shift-3 for GBP)
LVL 29

Expert Comment

ID: 39918985
The point of the keymap is to show the keycodes.  The keycode is what's important.  You can map any character to any keycode with xmodmap.
LVL 19

Author Comment

ID: 39921384

I too believe that there is a keyboard layout; but where is it???  I don't have a layout option for "GB Extended" and have tried various combinations on the command line, eg "setxkbmap gb-Extended", "gb-Extended-Winkeys" but all fail with "Error loading new keyboard description".

Is there anywhere else I can get it from?

serialband: I cannot see how to install xorg-xmodmap; I can download a tar file but what do I do with that?? The instructions I did find talk about downloading it from "official repositories" using pacman - I don't have that binary on my machine.  Can you please advise?

<Rant>Again, frustrated at how hard Linux makes it to download and install software.  Why can't there be a simple UI where you can just double click what you want?????</Rant>
LVL 29

Expert Comment

ID: 39921894
Can you just do yum install xmodmap on Oracle linux?  It should be the same "yellowdog update manager" that all redhat variants use.  I believe pacman is the archlinux package manager.  The package managers are quite easy once you learn the syntax.

Once installed, you can use xmodmap -pk to print the current keycodes to the screen.

Save it to a file for easy editing.
xmodmap -pk > UK_KeycodeLayout.keymap.

Some other articles about keyboard layouts.

If you really need a nice GUI installer, OpenSUSE & SUSE use Yast2 which you can point and click to install software in X.  On the command line, they use zypper.  Starting with Suse 12, you can install packages then check with zypper ps to see which processes need to be restarted later and restart them when you have time.
LVL 62

Expert Comment

ID: 39922035
Yours is very standard UK keyboard just like mine
with layout GB
bottom left key is
Bottom right

Winkeys are not part of ethnical keyboard layout printed on keys, they are part of keyboard model just like music keys or missing laptop keys.

Only difference from picture is that I have capital letters on keys, while you have small letters.
LVL 27

Expert Comment

ID: 39923291
I too believe that there is a keyboard layout; but where is it???  I don't have a layout option for "GB Extended" and have tried various combinations on the command line, eg "setxkbmap gb-Extended", "gb-Extended-Winkeys" but all fail with "Error loading new keyboard description".

Is there anywhere else I can get it from?

in my system there is a huge list available by clicking the little + sign down the list of the "input sources" tab which you will find in "countries and languages". i'm unsure about the exact names since my system is not currently in english. if you don't provide information regarding what you did or did not find and where, it is difficult to help. like i mentioned above, there is also a direct link to the input sources somewhere in the keyboard settings. likely you can also access thse settings by clicking on "gb" in your system tray if the languages snippet is active.

for xkbmap, you'll find documentation about variants here :
the manpage is ubuntu's but it also exists on your own system and is likely identical

what you typed just does not exist
$ setxkbmap yadaaa
Error loading new keyboard description

Open in new window

i tried "setxkbmap 'gb(extd)' " from the manpage and it does work. find the relevant part below

gb                               English (UK)                                                    |
       |gb(extd)                         English (UK, extended WinKeys)                                  |
       |gb(intl)                         English (UK, international with dead keys)                      |
       |gb(dvorak)                       English (UK, Dvorak)                                            |
       |gb(dvorakukp)                    English (UK, Dvorak with UK punctuation)                        |
       |gb(mac)                          English (UK, Macintosh)                                         |
       |gb(mac_intl)                     English (UK, Macintosh international)                           |
       |gb(colemak)                      English (UK, Colemak)                                           |

here is the resulting digit line with and without shift " 1234567 !"£$%^& "
looks good ?

<Rant>Again, frustrated at how hard Linux makes it to download and install software.  Why can't there be a simple UI where you can just double click what you want?????</Rant>

i'm not a linux fan (being more of a freebsd guy espetially because of the quality of the packaging system) but there is in all linux variants i ever used

i have no idea about "oracle linux", though, other than it is expensive (like oracle) -- or rather the support is--, that the white paper makes a fuss about features that are builin most linux variants (except for dtrace, but if you do need dtrace, better switch to bsd or solaris), and that i cannot find what package manager it is based on, much less which graphical tool would be builtin in less than 2 minutes googling like i would easily in any other linux variant

please don't rant against linux in general while you're only using a poorly documented version with the last installer (or rather runtime) that cannot detect a keyboard properly.

<rant ;) >
i'm not surprised there is no decent documentation given the fact it is crafted by Oracle. all links to whatever looks like a documentation is a bunch of commercial advertisement with little to no actual information.
LVL 19

Author Comment

ID: 39923467

I tried yum, and I now have xmodmap installed.


Thank you for that nice comment.

I can use the gb-extended layout now I know what it is called, but the problem with it is that shift-2 still gives me ",which is the same as the normal GB layout.  As I have said all along, I need shift @ (key to the right of colon and semicolon - see my image) to give me ", whilst maintaining the |\ of the bottom right hand key.

Now, according to what I have read above from gheist, my keyboard is classic UK.  So in Windows, when I change it to US, I think it must be *purely by chance* that the bottom right key (|\) still behaves in the desired way (for me) by giving me | and \.  I think this because, as shown on my diagram, when I change to US layout, the key with the hash and tilde on it (immediate left of enter) changes to give me | and \, which I presume is where this key would be located on a natural US keyboard.

So, what I need to do then is hack my UK keyboard layout to swap the @ and " keys...
I have re-read the previous posts here and searched on the net, but haven't seen any examples of how to achieve this.

Can someone please advise on the script/whatever is required to modify these two keys with xmodmap?
LVL 62

Expert Comment

ID: 39923586
so you need a custom keyboard layout
Ubuntu keeps instruction here
LVL 29

Expert Comment

ID: 39923687
Now that you have xmodmap installed, have you tried running xmodmap -pk > gb-exteneded.keymap to generate a new keymap.  You can then modify the keymap and reload it with xmodmap gb-extended.keymap.
LVL 27

Expert Comment

ID: 39926145
i do not believe your layout does not exist but i do not have time to try all us layouts to find the proper one. you should at least try to look the name of the layout in windows and see if it exists in the man page i gave you above.

then to swap keys :

advice : create a new keymap as serialband suggested above so you don't mess with existing keymaps. switch to this keymap.

get the keycode for first key
$ xmodmap -pke | grep quotedbl
keycode  12 = quotedbl 3 quotedbl 3 numbersign sterling numbersign

Open in new window

(beware mine is 12 but yours will likely be different)

get the keycode for second key
$ xmodmap -pke | grep ' at '
keycode  19 = agrave 0 agrave 0 at degree at
keycode  38 = q Q q Q at Greek_OMEGA at

Open in new window

the proper one is the first on my keyboard.
if you are unsure, look at the adjacent keys (given by the keycode + or - 1)
notice that i do not directly have @ which is why "at" is not the first field (i have to type ATGR+0)

swap those keys
xmodmap -e "keycode  19 = quotedbl 3 quotedbl 3 numbersign sterling numbersign"
xmodmap -e "keycode  12 = agrave 0 agrave 0 at degree at"

Open in new window

would swap the keys on my keyboard including the ALTGR and SHIFT variants
LVL 19

Accepted Solution

mrwad99 earned 0 total points
ID: 39926697
OK.  I have managed to somehow cobble together settings which give me the combinations of keys I am after, *without hacking any layouts*.  The screenshot below shows my keyboard preferences dialog.

Layout dialog
If I remove any item in the list, or if I restart my machine, I lose the required combination.  To get it back after a restart, I have to delete the bottom element "...AltGr dead keys" and then re-add it.  Then everything works as required.

I have no idea why this is.  I also don't see why I need multiple layouts present for this to work.  Note that the "...AltGr dead keys" layout does not work when it is the only item in the list.

I am not particularly pleased about this behaviour, but at least I have the required layout.  If anyone has any input on why this could be, please do share, otherwise I shall split the points and put this whole rather frustrating episode behind me :)
LVL 27

Assisted Solution

skullnobrains earned 167 total points
ID: 39928784
if i'm not mistaken, you are only using a single layout, most likely the last one if removing+readding it makes a difference. i believe that removing other layouts selects the first one automagically or some similar artifact led you to feel differently (?)

note that setting the keyboard model properly may help a lot. default should be pc-105. in some cases a weird keymap is brought by selecting the wrong keyboard type.


as far as restart is concerned, here is a little background :

- there is a layout defined at console-level (which you probably never set)
- there is a layout defined in xorg.conf, which is used when the x server starts
- there may be layouts defined in any of the x startup scripts
- there may be layouts defined in the sessioin manager (likely gdm in your case)
- there is a layout defined in your gnome desktop

usually, all of this mess happens to work pretty fine :
under a desktop linux,
- you never see the console
- xorg is set to autodetect layouts (and usually does so properly) or was properly configured at install time
- all the other ones keep the existing layout

also note that this mess does have a use : it permits things like running 2 desktops associated with different screens and keyboards with different layouts on the same machine for example


there is a known bug (?) in gnome : whatever layout you define, gnome will start with the existing layout, and you'll need to click on the little "us", "gb" or whatever icon that represents your keyboard or just revalidate your setting for gnome to do the job.

this is most likely a bug added voluntarily because gnome comes preset with an us keyboard, and users of other layouts like myself would rather have gnome leave the keyboard alone unless instructed otherwise. the guy who made the "correction" just removed the automatic layout setting rather than add a "leave my keyboard alone" option and make it the default.

this idiotic bug has been around for years and i do not expect it to be corrected any time soon (unless any one of us has enough time to take care of it)

other desktops such as kde or xfce behave properly in this respect : default to "no interference" and behave as expected if you set a layout


it is very likely in your case that oracle linux detected another keyboard at install time and stuck this in whatever config file they deemed fit.


bottomline is once you find the proper setxkbmap command, it will most likely be easier to set it up to run when your session start than fight with the gnome. sticking that command in the startup script of the display manager or in startx would be meaningfull as well if it is not overriden later along the way by whatever oracle has setup, but more complicated and rather useless unless you need <@> or <"> to type your password
LVL 19

Author Closing Comment

ID: 39949789
I have accepted my own answer as the "best" solution since it shows how this problem was eventually solved, but have split the points amongst you three for the superb assistance you have given me throughout this question.

Many thanks to you all for your support :)

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question