Keyboard input/Keypress check: Difference between revisions

→‎{{header|C}}: flush stdin and stdout before reading a keypress
No edit summary
(→‎{{header|C}}: flush stdin and stdout before reading a keypress)
Line 587:
=={{header|C}}==
For POSIX systems. Ctrl-C to stop:<lang C>#include <stdio.h>
#include <termios.h> /* general terminal interface: tcgetattr, tcsetattr, tcflush */
#include <unistd.h> /* synchronous I/O multiplexing: select, FD_CLR, FD_ISSET, FD_SET, FD_ZERO */
#include <unistd.h>
#include <fcntl.h>
 
Line 628:
while(1) {
set_mode(1);
/* force C library buffers to be written to kernel buffers,
and flush pending input to avoid previously pressed keys */
fflush(stdout);
while (!(c = get_key())) usleep(10000);
printf("key %d\n", c);