source: abuse/trunk/src/keytest.cpp @ 97

Last change on this file since 97 was 56, checked in by Sam Hocevar, 11 years ago
  • Add licensing terms to most C / C++ files (Ref #5).
File size: 1.3 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *
5 *  This software was released into the Public Domain. As with most public
6 *  domain software, no warranty is made or implied by Crack dot Com or
7 *  Jonathan Clark.
8 */
9
10#include "config.h"
11
12#include <fcntl.h>
13#include <sys/types.h>
14#include <sys/time.h>
15#include <stdlib.h>
16#include <stdio.h>
17#include <stdio.h>
18#include <unistd.h>
19#include <getopt.h>
20#include <signal.h>
21#include <termios.h>
22#include <linux/kd.h>
23#include <linux/vt.h>
24#include <linux/keyboard.h>
25#include <sys/ioctl.h>
26#include <sys/stat.h>
27
28
29int fd_ready_to_read(int fd)
30{
31  struct timeval tv={0,0};
32  fd_set kbd_set;
33  FD_ZERO(&kbd_set);
34  FD_SET(fd,&kbd_set);
35  select(FD_SETSIZE,&kbd_set,NULL,NULL,&tv);
36  return (FD_ISSET(fd,&kbd_set));
37}
38
39
40
41
42
43int key_fifo()
44{
45  int fd,child_pid;
46  FILE *fp;
47  fp=popen("keydrv","r");
48  fscanf(fp,"%d",&child_pid); 
49  pclose(fp);
50  do
51  { usleep(10000);
52  } while (access("/tmp/jckey-driver",R_OK));
53  fd=open("/tmp/jckey-driver",O_RDONLY);
54  return fd;
55}
56
57
58main()
59{
60  unsigned char key;
61 
62  int console_fd=key_fifo();
63  while (1)
64  {
65    if (fd_ready_to_read(console_fd))
66    {
67      read(console_fd,&key,1);     
68      printf("read key (%d)\n\r",(int)key);
69    } else usleep(10000);         
70  } 
71}
Note: See TracBrowser for help on using the repository browser.