Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect meta (special) keys (Ctrl, Shift, Alt, Tab, Esc, Backspace) from Shell Input

I want to know if anybody knows how to detect meta (special) keys (Ctrl, Shift, Alt, Tab, Esc, Backspace) from Shell Input.

I've seen posts that explain how to detect arrow keys and such, but not the above special keys.
Is there any way I can do $ showkey -s and use the raw scan-code to somehow get the key input?

Any kind of help will be much appreciated!!

like image 670
sonic98 Avatar asked Nov 23 '11 12:11

sonic98


2 Answers

In general, you cannot do it. That said:

  • X11 sends KeyPress and KeyRelease events.
  • The Linux console provides a set of ioctls that allow low-level access to the keyboard, documented at console_ioctl(4). You would set the keyboard to RAW or MEDIUMRAW mode (don't confuse these modes with termios' raw mode, they are not related at all).
like image 72
ninjalj Avatar answered Sep 23 '22 14:09

ninjalj


I'm not sure it always make sense. The tty discipline is doing something (details are gory). Perhaps you need a helper program (e.g. in C, which would use a library like ncurses or readline) such as dialog!

like image 39
Basile Starynkevitch Avatar answered Sep 20 '22 14:09

Basile Starynkevitch