Re: general i/o question

看板FB_hackers作者時間17年前 (2008/05/08 06:33), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串5/6 (看更多)
On Wed, 7 May 2008 14:40:57 -0700 Jeremy Chadwick <koitsu@freebsd.org> wrote: > On Wed, May 07, 2008 at 05:39:00PM +0200, rmgls@free.fr wrote: > > i need to test (NOWAIT), the presence of keypressed/depressed on a terminal > > and then read the scan code, like for a piano pc keyboard. > > > > my questions are as follows: > > > > 1. is it a general C function which may scan a terminal without waiting? > Regarding I/O without waiting: there is not a general libc function for > this. Garrett mentioned getc(), which blocks (waits). getc won't tell you whether a key is pressed or not in any case, just that a key *has been* pressed when it returns. This question is normally tied back to some DOS getc-like call that didn't block, but returned null if a key hadn't been pressed. The standard way to do that is select() (now poll). The problem with both of those is that - again - they won't tell you whether or not a key *is* pressed, but only whether one *has been* pressed. > You might want to consider seeing if the kqueue/kevent stuff on the BSDs > will work with pty/tty input. You can use that to set up an event in > the kernel which tells the kernel "run function XYZ when I/O is seen on > this fh/fd". It's like select() in that respect, but is faster. Yes, they'll work with it. The question is - can you get the information about whether or not a key is currently pressed that way? Since X gets the information, its' there - but it's not clear how close to the hardware X has to get to get it. <mike -- Mike Meyer <mwm@mired.org> http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. O< ascii ribbon campaign - stop html mail - www.asciiribbon.org _______________________________________________ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
文章代碼(AID): #188Yut00 (FB_hackers)
文章代碼(AID): #188Yut00 (FB_hackers)