Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I tried to use xmodmap to map META_L to the MENU key but it doesn't seem to be accepted by bash as the meta key. So, I am wondering how these components (keyboard, X, xterm, bash) relate to each in regard the the Meta- and Super-Keys. Any explanation would be appreciated.

Let me put this another way. The bash man page says, for example, that the function yank-nth-arg is bound to M-C-y and it works when I press Esc-Control-y. But I find this a bit cumbersome. So how can I make bash accept another key as Meta (like the Menu) for all its default bindings?

share|improve this question
    
Is your MENU key even noticed by X? What window manager are you using - some of them can help you redefining your keys. –  choroba Jan 13 '12 at 8:24
add comment

2 Answers

The key event is generated by the X server (as configured by xmodmap), and is sent to your X application. Your window manager could intercept this before it is sent to xterm. XTerm, in turn, translates the event to some bytes and sends the bytes to the pseudo-tty allocated by your shell, bash.

Please note that not all events are translated directly to bytes by XTerm. For instance, the Ctrl and shift keys, by themselves, generate X keyboard events, but XTerm sends nothing to the shell (or other application) running within it. This also includes the Meta key by itself, but not the Menu key. However, the event generated by pressing Meta-e will make XTerm send either the byte 0xE5 or the two-byte sequence 0x1B 0x65, depending on the XTerm.VT100.metaSendsEscape resource setting.

share|improve this answer
add comment

The mapping from keyboard keys to modifiers like Meta and Control is handled by the X server (i.e. the low-level part of the GUI). This mapping can be manipulated through the old-style xmodmap command or the new-style XKB interface, or through a GUI configuration tools that uses one of these under the hood.

By default, on most setups, the Meta key is the key labeled Alt. This is because historically, many unix workstations had a key labeled Meta where PCs have a key labeled Alt. So if you have a binding for M-C-y, press Ctrl+Alt+Y.

To check what your current bindings are, start the xev program in a terminal. With the xev window focused, press keys; you'll see a transcript of the generated events in the terminal.

The communication between terminal emulators (or terminal devices corresponding to a physical terminals) and applications uses characters. When you press A, the terminal receives the information “A key, no modifier”, but what it sends to the application running in the terminal is the character a. When you press a function key like Up or F1, there's no corresponding character; the terminal sends a character sequence beginning with the escape character (byte 27, sometimes written \e or ^[). When a terminal emulator such as xterm received a key press event with the Meta modifier, it translates that key to an escape character followed by the key's underlying function, e.g. \ea (escape, lowercase a) when you press Meta+A.

What is the exact difference between a 'terminal', a 'shell', a 'tty' and a 'console'? may be useful background.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.