[<<] [<] Page 1 of 1 [>] [>>] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Subject:
reading the keyboard
From: Yan Seiner ####@####.#### Date: 10 Dec 2005 18:44:42 +0000 Message-Id: <439B2181.7050705@seiner.com> I am trying to run nano-X progs from init.... One of the programs needs to read the keyboard. Here's the code: FD_ZERO (&rfds); FD_SET (0, &rfds); printf ("k0: %d %d %d\n", k, delay, retval); retval = select (1, &rfds, NULL, NULL, &tv); printf ("k1: %d %d %d\n", k, delay, retval); if (retval) { buffer[0] = '\0'; printf ("waiting for ch: %d", read (0, buffer, 1)); ............. } What happens is that select returns with a 1, but read() blocks. If I open /dev/stdin O_NONBLOCK, then read() returns -1, signifying an interrupted read. I can hold a key down, and I will occasionally get read() to read the correct char.... So, how do I read the keyboard? Or, how do I automatically start (and restart) nano-X apps so that they have access to the keyboard input? --Yan | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Subject:
Re: [nanogui] reading the keyboard
From: "Greg Haerr" ####@####.#### Date: 10 Dec 2005 20:44:49 +0000 Message-Id: <010801c5fdca$99a86be0$6401a8c0@gregnewport> > I am trying to run nano-X progs from init.... > So, how do I read the keyboard? > > Or, how do I automatically start (and restart) nano-X apps so that they > have access to the keyboard input? The problem with keyboard input from app started from init isn't usually handling the read code differently, but instead has to do with opening the correct tty, and handling the problems resulting from not having a "controlling" tty. I can't remember all the details offhand, but UNIX kernels used to handle tty reads differently after fork() and other times depending on whether the process had a controlling tty. Also, there are sometimes differences when apps assume that 0,1 & 2 are open. You didn't mention your open code, does this application work entirely correctly not from init? Regards, Greg | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
[<<] [<] Page 1 of 1 [>] [>>] |