Differences between ncurses library and termios struct w.r.t Keyboard reading
I want to read a pressed key or a combination of pressed keys from the keyboard and perform some action afterwords.
e.g. Ctrl-Alt-F1 Out of ncurses lib. and the termios struct which can be used best for the above purpose and why ? I tried to search on Google, the differences between these two but couldn't get much ! Kindly guide ! |
"curses" is relatively high-level; "termio" is extremely low-level.
If you're talking about one low-level key input in one specific part of your program, and termio gives you what you want - then go for it. If you want generalized, cross-platform, "text mode screen handling" capabilities, then ncurses is generally an excellent choice. If you just want to read the raw, binary input of a specific key or key combination and you can get away with standard "printf" and "scanf" type input for the rest of your program, then "termio" might be the better choice. IMHO .. PSM |
I'm sure others have different opinions, but here's my take. If you want much of what ncurses offers (character-oriented windows, subwindows, menus, and the like), use ncurses. Otherwise, stick with struct termios, so you don't add needless complexity to your program's functionality.
|
paulsm4
and wje_lq Many thanks to both of you for these enlightening replies ! I used termios for the above task as i too soon realized that ncurses would be too heavy for all this ! I have shown my C code in the next post. Quote:
Would you be kind enough to tell me what does this mean so that i can respond accordingly ? |
Compiled C Code for reading key-strokes from keyboard !
Important Link:
http://www.win.tue.nl/~aeb/linux/kbd...odes.html#toc1 Code:
#include <stdio.h> |
Hi -
Quote:
"PSM" is just my initials ("Paul Michael John Santa Maria" ;)) Glad we were able to help! |
Thanks for the explanation Paul,
You know I looked for the slang PSM on Google and found "Please See Me". Then I wondered that how do you want me to respond to that ! :D |
...
Thank so much TheIndependentAquarius ._____.
|
A note: termios(2) won't read anything, read(2) will. Decoding/interpreting escape sequences is no way trivial; for example midnight commander does some interesting dark magic so that Shift+F5 would work as F15 (instead of F17 or whatnot.)
|
All times are GMT -5. The time now is 05:31 PM. |