maixy wrote:
> 
> Hi all,
>   I want to get the character while I strike any key,I try to use getchar(),but it 
>need to strike ENTER to end of string,can I get the value of key immediately before I 
>strike ENTER.In DOS,I can use kbhit() to check if there is any key to be striked,but 
>how can I do in linux?
>   I have no idea how to get the key. Do you have any idea?
> 
Here is a blocking version:

char get_key()
{
        static struct termio my_kb, orig_kb;
        static int first = 1;
        char ch;
        if (first) {
                first = 0;
                ioctl(0, TCGETA, &orig_kb);
                my_kb = orig_kb;
                my_kb.c_lflag &= ~(ECHO | ISIG | ICANON);
                my_kb.c_cc[4] = 1;
        }
        ioctl(0, TCSETAF, &my_kb);
        ch = getchar();
        ioctl(0, TCSETAF, &orig_kb);
        return ch;
}

Note that with it installed you cannot do CTRLC. Adapt it to your need.
I also think that by using ncurses you might solve your problem a la
DOS.

Ciao, Paolo.
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
--
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/

Reply via email to