Re: reg getch() function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tuesday 28 December 2004 15:12, ram wrote:
> Can anyone tell me how to write a getch fucntion using the GETATTR
> and SETATTR  commands.The functions should be like " when we click
> the button the key board should display the button pressed.THis can
> be done but what about the escape sequence buttons like uparrow and
> down arrow.

This is the wrong list for this question, I'm pretty sure. But, just for 
fun, I'm including code that answers your question. The up and down 
arrows are shown by a sequence of ascii chars ^[[A ^[[B, etc. etc.

have fun,
-- 
-jeff
/*------------------------------------------------------------------
 *	keys.c	read keybd, show dec, hex, and ascii
 *------------------------------------------------------------------
 */

#include <sys/ioctl.h>
#include <termio.h>

main()
{
    struct termio t1, t2;
    unsigned char in[2];
    int len;

    ioctl(0, TCGETA, &t1);
    t2 = t1;

    t1.c_lflag = 0;
    t1.c_iflag = 0;
    t1.c_cc[VMIN] = 1;
    t1.c_cc[VTIME] = 0;
    ioctl(0, TCSETA, &t1);

    printf("\n");
    while(1)
    {
	len = read(0, in, 1);
	if (len < 1)
	{
	    printf("\nError during read !!\007");
	    exit(1);
	}
	*in &= 0xFF;
	printf("dec(%d), hex(%2x)", *in, *in);
	if (*in >= 32 && *in <= 127)
	{
	    printf(" ,ascii(%c)", *in);
	}
	printf("\n");

	if (toupper(*in) == 'Q')
	{
	    ioctl(0, TCSETA, &t2);
	    exit(0);
	}
    }
}

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Fedora Announce]     [Fedora Kernel]     [Fedora Testing]     [Fedora Formulas]     [Fedora PHP Devel]     [Kernel Development]     [Fedora Legacy]     [Fedora Maintainers]     [Fedora Desktop]     [PAM]     [Red Hat Development]     [Gimp]     [Yosemite News]
  Powered by Linux