Zeichen von Tastatur einlesen in C

Post Reply
Message
Author
andy
Posts: 150
Joined: 07. Nov 1999 12:51
Location: Kiel
Contact:

Zeichen von Tastatur einlesen in C

#1 Post by andy »

Moin,

wie kann ich in C ein einzelnes Zeichen von der Tastatur einlesen, ohne
daß es
auf den Bildschirm angezeigt wird und ohne das die Eingabe durch ein
return
bestätigt werden muß? Wahrscheinlich muß ich da doch
irgendwie den Tastaturpuffer umgehen, aber wie ?

Ciao, Andy


andy
Posts: 150
Joined: 07. Nov 1999 12:51
Location: Kiel
Contact:

Re: Zeichen von Tastatur einlesen in C

#3 Post by andy »

danke für die Tips, ich habe jetzt ein Beispiel unter
www.tldp.org/HOWTO/NCURSES-Programming-HOWTO/ gefunden:


#include <ncurses.h>
int main()
{
int ch;
initscr(); /* Start curses mode*/
raw(); /* Line buffering disabled*/
keypad(stdscr, TRUE); /* We get F1, F2 etc..*/
noecho(); /* Don't echo() while we do getch */

printw("Type any character to see it in bold
");
ch = getch(); /* If raw() hadn't been called
* we have to press enter
before it
* gets to the program*/
if(ch == KEY_F(1)) /* Without keypad enabled this will */
printw("F1 Key pressed");/* not get to us either*/
/* Without noecho() some ugly
escape
* charachters might have been
printed
* on screen*/
else
{ printw("The pressed key ASCII value is ");
attron(A_BOLD);
printw("%d", ch);
attroff(A_BOLD);
}
refresh(); /* Print it on to the realscreen */
getch(); /* Wait for user input */
endwin(); /* End curses mode */

return 0;
}



das ganze dann compiliert:
[root@andy /]# gcc -otaste -lcurses taste.c
...klappt


Ciao, Andy

Post Reply