How to replace the ESC key on Ubuntu?

Source: Internet
Author: User

I recently split my laptop, but I accidentally broke the ESC key when I installed it. I didn't have any money to change my laptop keyboard, so I had to drum up the network to replace the ESC key.

I want to use the ESC key for VI, and I need to use it when I exit some system menus in Ubuntu. In vim, you can press Ctrl + [to replace ESC to switch between different modes. However, there are no other shortcut keys in Ubuntu to replace the ESC key, you can only bind other uncommon buttons to the ESC key. I searched the internet and found an article. Under the guidance of this article, I replaced the uncommon contrl_r (right ctrl key) with the ESC key.

The specific method is to create a. xmodmap file in the user's home directory, enter the following code in it, and restart it:

1        remove Control = Control_R 2         3        keycode 9 = Control_R 4         5        keycode 105 = Escape 6          7        add Control = Control_R8    

For details, refer to the following articles:

Http://blog.163.com/abe618@126/blog/static/164543642201062172520529/

Replace keys on the keyboard in Ubuntu
First, you need to know the keycode of each key on the keyboard. You can use Xev to check the keycode on a computer with the same keyboard layout.

We know that the keycode of ESC is 9, and the symbol is "escape". We want to replace it with winkey (that is, the windowslogo button)

The keycode of winkey is 115.

Then ~ Create. xmodmap in the/($ home) Directory (if not, create it ):

Gedit ~ /. Xmodmap

Add the following sentence:

Keycode 115 = escape

(Define keycode 115 as the escape button)

Then logout and login will be OK. Http://www.cbi.pku.edu.cn/chinese/documents/csdoc/cman/xmodmap.html

This URL details the usage of xmodmap. Xmodmap is a powerful tool for modifying the key position. Haha, save a sum of money.

Xmodmap-adjust keyboard ing and mouse key ing in X Environment

Xmodmap is used to edit or display the modifier map and keymap table of the keyboard ),
The customer program uses them to convert the keycode event to keysym. Generally, xmodmap is used in the startup script of the user session
Configure the keyboard as your favorite style.

Xmodmap [-options...] [filename]

Options)

Xmodmap can use the following options:

-Display display

This option specifies the host and display.

-Help

The command line parameter description is displayed on the standard error device. If an unrecognized parameter is displayed, xmodmap will also execute this function.

-Grammar

This option displays the expression syntax on a standard error device. This syntax applies to file or-e expression options.

-Verbose

This option requires xmodmap to display log information when analyzing input data.

-Quiet

This option requires that verbose log information be disabled. This is the default option.

-N

This option does not require xmodmap to really change (keyboard, mouse) ing, but only shows what it may do, just like the same options of make (1.

-E expression

This option executes a given expression. You can specify any number of expressions on the command line.

-PM

This option requires that the current modifier ing be displayed on the standard output device.

-PK

This option requires that the current keyboard ing table (keymap) be displayed on the standard output device ).

-PKE

This option requires that the current keyboard ing table (keymap) be displayed on the standard output device. The output format can be used as the input of xmodmap.

-PP

This option requires that the current mouse (pointer) ing be displayed on the standard output device.

-

A separate hyphen (-) indicates that the standard input device is used as the input file.

Filename specifies a file that contains the expression that xmodmap will execute. This file is usually named. xmodmaprc and is stored in the user's root directory.

(Let's take a good look at the xmodmap usage in the url I gave. I will not repeat it here .)

The following uses my own example to explain how it works.

If neither of my shift keys can be used (Bad keys), I can only find other keys to replace them. Well, right CTRL is selected (shift is replaced by right CTRL .)

First, enter

Xmodmap-PKE

-PKE

This option requires that the current keyboard ing table (keymap) be displayed on the standard output device. The output format can be used as the input of xmodmap.

The following output is displayed:

...

Keycode 61 = slash question

Keycode 62 = shift_r

...

Keycode 108 = kp_enter

Keycode 109 = control_r

Key code 110 = pause break

Key code 111 = print sys_req

.......

If the keycode 62 = shift_r and keycode 109 = control_r are not displayed, the two lines are pulled. If you replace them with one, OK.

Next, create the file. xmodmap in the $ home directory,

For example, kytor @ kytor-desktop :~ $ Gedit. xmodmap

Enter the following content:

Remove shift = shift_r

Remove control = control_r

Keycode 62 = control_r

Keycode 109 = shift_r

Add shift = shift_r

Add control = control_r

OK, save.

After restarting, it will prompt whether to load. xmodmap. If you select Yes, it will be OK. Xmodmap only changes the keysym of X. Invalid for the terminal. First, find a keyboard, replace the bad keyboard, enter the system, and create a text file named dumpkey. The content is very simple:

Code: dumpkeys> newkey. Map

You cannot press ">" because the keyboard with the shift key is broken ". Then shut down, replace the bad keyboard, and enter the system.

Add execution permission to the dumpkey File

Chmod 755 dumpkey

Then execute

./Dumpkey

Generate the newkey. map file in the current directory and edit it. For example, some of my contents are as follows:

Code: keycode 117 = f17

Altgr control keycode 117 = voidsymbol

Shift Alt keycode 117 = voidsymbol

Key code 118 = kp_minplus

Altgr control keycode 118 = voidsymbol

Shift Alt keycode 118 = voidsymbol

Key code 119 = pause

Key Code 120 =

Key Code 121 =

Key Code 122 =

Key Code 123 =

Key Code 124 =

Key Code 125 =

Key code 126 =

Key Code 127 =

Keycode 128 = NUL

Altgr control keycode 128 = voidsymbol

Shift Alt keycode 128 = Vo idsymbol

Keycode 129 = NUL

Altgr Control

Keycode 129 = voidsymbol

Shift Alt

Keycode 129 = voidsymbol

Keycode 130 = NUL

Note: keycode 120 to 127
No definition. It indicates whether there are any keys on your keyboard. You can change one of them to the one you want to define, as to which key code corresponds to which key on the keyboard, you have to try it by yourself.
The showkey command is not accurate either. I am too lazy to search for it. I just changed it to = shift.

Of course, if there is no idle key, you need to switch the keycode of the two keys.

Save and exit. Run the code loadkeys newkey. Map.

Now, try to see if some keys can be used for shift.

If you can use it, you can write loadkey/Your/DIR/of/newkey. map to the script that runs automatically upon startup, so you don't have to lose it every time.

It should be noted that this method is only useful for text mode and does not work if you enter XWindow. xmodmap is used below x.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.