September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,46 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
void set_mode(int want_key)
|
||||
{
|
||||
static struct termios old, new;
|
||||
if (!want_key) {
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &old);
|
||||
return;
|
||||
}
|
||||
|
||||
tcgetattr(STDIN_FILENO, &old);
|
||||
new = old;
|
||||
new.c_lflag &= ~(ICANON | ECHO);
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &new);
|
||||
}
|
||||
|
||||
int get_key()
|
||||
{
|
||||
int c = 0;
|
||||
struct timeval tv;
|
||||
fd_set fs;
|
||||
tv.tv_usec = tv.tv_sec = 0;
|
||||
|
||||
FD_ZERO(&fs);
|
||||
FD_SET(STDIN_FILENO, &fs);
|
||||
select(STDIN_FILENO + 1, &fs, 0, 0, &tv);
|
||||
|
||||
if (FD_ISSET(STDIN_FILENO, &fs)) {
|
||||
c = getchar();
|
||||
set_mode(0);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int c;
|
||||
while(1) {
|
||||
set_mode(1);
|
||||
while (!(c = get_key())) usleep(10000);
|
||||
printf("key %d\n", c);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
#include <stdio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
char chr = getchar();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue