Monday, 7 October 2013

Remap the keys in any key board in Ubuntu


All the Ubuntu users may be thinking of changing the function of the keys in their key boards. Now we can change the functions of the keys and make them function as we want them to. Lets know how to do it? First of all we need to now the function of a particular which we want to change. Now as we know the function of the keys we can proceed on to the concept of changing their functions. First go to the terminal in Ubuntu. Then type the command xev the Terminal and press Enter. Then we will get the terminal like this as shown below:

Here this command tracks the key strokes with which we can change their functions. Now after entering the command we got a window. Now what we need to do is just press the keys which we want to remap. Now for example I want to re-map the PAGE UP key with PAGE DOWN. First we have to press the PAGE UP key. Then we will get the output in the terminal like this as shown below


Pressing Up produces keycode 111, assigned to action Up.

KeyPress event, serial 34, synthetic NO, window 0x3a00001,
root 0xa5, subw 0x0, time 13739005, (165,-16), root(170,32),
state 0x0, keycode 111 (keysym 0xff52, Up), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False

Here note the key code we obtained in the above output as
keycode 111 (keysym 0xff52, Up)

Pressing Down produces the kyecode 116, which is assigned to the action Down.

KeyPress event, serial 31, synthetic NO, window 0x3a00001,
root 0xa5, subw 0x0, time 13735531, (165,-16), root(170,32),
state 0x0,
keycode 116 (keysym 0xff54, Down), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False

Here note the key code we obtained in the above output as
keycode 116 (keysym 0xff54, Down)

Type this command in the terminal to change the function of the prescribed key.

xmodmap -e "keycode 111 = Down
 
In the above command Key code 111 is the code of the PAGE UP key and as we are placing the term as DOWN in the above command the function of the PAGE UP key changes to DOWN.

The input in the command is given like this. We have got the two outputs by pressing the two keys. And we have to observe these lines in the output obtained
state 0x0, keycode 111 (keysym 0xff52, Up), same_screen YES,

and

state 0x0, keycode 116 (keysym 0xff54, Down), same_screen YES,

Key code 111 is for UP and Key code is for DOWN. So now we changed the keycode of UP to DOWN.
Like this we can change the function of other keys also by observing the keycodes and their designations in the lines in the output as shown in the above line in BOLD phase. To get these changes for every session, after issuing the commands above, create a file called .Xmodmap (or any thing), with the following command:

xmodmap -pke > .Xmodmap


Then, create a file called .xinitrc in your home directory, containing just the following line:

xmodmap .Xmodmap
That's all you can use that key to do the function of another key.


No comments:

Post a Comment