LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 04-19-2014, 11:09 AM   #1
SteveThePirate87
Member
 
Registered: Jul 2012
Location: Glasgow, UK
Distribution: Ubuntu Mate 15.04
Posts: 66

Rep: Reputation: Disabled
Remap a missing keyboard key to another one


Hi,

Does anyone have any idea how to remap a key that doesn't exist on the physical keyboard to another key?

Basically I bought a keyboard online which is meant for "gaming" but I bought it because it looked good, and I just realised when i was kicking about on the terminal that the left shift key had been extended and it has frustratingly ended up with a missing pipe and backslash key. I basically want to re-write them to some other ones such as the / and * num keys but can't even use xev to find out the keycode because it isn't there to press.

Does anyone have any idea how I would remap this missing key? I use a UK layout if that helps and run Mint 16 Cinnamon.

Cheers

Steve
 
Old 04-19-2014, 04:56 PM   #2
Philip Lacroix
Member
 
Registered: Jun 2012
Distribution: Slackware
Posts: 441

Rep: Reputation: 574Reputation: 574Reputation: 574Reputation: 574Reputation: 574Reputation: 574
Hi. You will have to deal with this separately for the X server and for the command line interface.

To remap a key for the command line (note that this will not affect X terminal emulators, for which you have to configure xkb - please see below) run the command 'showkey' first, in order to know the relevant keycode: just run 'showkey' and press the key to which you want to remap, then wait for 10 seconds to let the program stop. The kbd keymap used by your system is probably 'uk.map' and its location should be something like '/usr/share/kbd/keymaps/i386/qwerty/'. Make a backup copy of the compressed map file (e.g. 'uk.map.gz') and decompress it with gzip:

Code:
# gzip -d uk.map.gz
By the way, on Slackware I can see which layout is loaded at boot time in the script '/etc/rc.d/rc.keymap', however on Mint this should be somewhere else in '/etc/init.d/'. Edit the decompressed keymap file by adding a line at the proper place for the relevant keycode. Let's say that you want to use the right 'Win' key (code 126) for the backslash and the pipe, so you may add a line like this:

Code:
keycode	126 = backslash	bar
Compress the file again and reload the keymap:

Code:
# gzip uk.map
# loadkeys uk.map.gz
This way you will obtain the backslash by pressing the right 'Win' key, and by using it with "Shift" you will get the pipe instead.

As mentioned, the above will affect the command line terminal alone. Regarding the X server, it is somewhat simpler. You need to add a rule to the relevant symbols file for xkb, which you should find in '/usr/share/X11/xkb/symbols/'. In your case you will probably have to edit the file named 'gb'. In order to obtain a result similar to the above, add a line like this to the "Alphanumeric section":

Code:
key <RWIN> { [ backslash, bar ] };
The documentation for xkb will be useful to identify the right code for a given key. Restarting the X server should be enough in order to load the modified map. I have no idea if conflicts of some kind may arise under certain conditions with this kind of key re-mappings: I didn't notice any issues so far.

<Edit>
As an alternative, these will use the '/' key of the numpad: "Shift + /" will print the backslash, while "Alt-Gr + /" will print the pipe. HTH.
Code:
keycode	98 = slash  backslash  bar
key <KPDV> { [ slash, backslash, bar ] };
Oh, and at least the pipe should already be mapped as "Alt-Gr + TLDE".
</Edit>

Regards,
Philip

Last edited by Philip Lacroix; 04-20-2014 at 03:13 PM. Reason: link to xkb doc; clarif.; lex.; |
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Key remap interndan Slackware 14 03-08-2012 11:27 AM
How do I remap Alt to a Super Key? fhsm Linux - Newbie 4 01-15-2009 05:40 AM
Key remap Silverdaz Linux - Software 1 07-08-2004 11:35 AM
remap keyboard windows key khtse Slackware 2 07-01-2004 01:14 PM
Key remap Silverdaz Fedora 0 06-23-2004 08:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 02:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration