PDA

View Full Version : reading keyboard events from CLI?



TheHimself
December 31st, 2009, 12:28 AM
How can one write a shell script that would do certain things if a specific key combination is pressed?

Also a related question: how can one run an application without allowing it to read (and act upon) keyboard events?

Than you.

blazemore
December 31st, 2009, 12:37 AM
That's real-time programming, not shell scripting.
Any key combinations would be interpreted by the shell/window-manager, not your program.
The only exception would be Ctrl+C, which programs can use to exit cleanly if they want, I think you could get it to do something else; bit of a hack though.

TheHimself
December 31st, 2009, 02:45 PM
Yes, it's interpreted by shell/window-manager but then it's passed to the program/window which is in focus. That's how hotkeys in applications work. Also there are CLI programs which have menus. I want to know how to employ this.

My second question is this: how can one simultaneously run two applications from CLI?

hessiess
December 31st, 2009, 08:50 PM
Ncurses.

falconindy
December 31st, 2009, 11:17 PM
Yes, it's interpreted by shell/window-manager but then it's passed to the program/window which is in focus. That's how hotkeys in applications work. Also there are CLI programs which have menus. I want to know how to employ this.

My second question is this: how can one simultaneously run two applications from CLI?

Look at the source code for DWM (http://dwm.suckless.org/). it's only 2000 lines and is coded very cleanly. It employs the use of a "master" mod key plus modifiers and a letter/number to accomplish a task.

This (http://tldp.org/LDP/gs/node5.html) is a decent intro on Linux's job control.