34632b6de9017684f895754708680a8484a8e2f3
[oftp] / src / dos / input.c
1 #include <conio.h>
2 #include "input.h"
3
4 int init_input(void)
5 {
6         return 0;
7 }
8
9 void cleanup_input(void)
10 {
11 }
12
13 static int conv_special(int key)
14 {
15         switch(key) {
16         case 72:
17                 return KB_UP;
18         case 80:
19                 return KB_DOWN;
20         case 75:
21                 return KB_LEFT;
22         case 77:
23                 return KB_RIGHT;
24         case 71:
25                 return KB_HOME;
26         case 79:
27                 return KB_END;
28         case 82:
29                 return KB_INS;
30         case 83:
31                 return KB_DEL;
32         case 73:
33                 return KB_PGUP;
34         case 81:
35                 return KB_PGDN;
36         default:
37                 break;
38         }
39
40         if(key >= 58 && key <= 70) {
41                 return KB_F1 + (key - 59);
42         }
43
44         return -1;
45 }
46
47 int poll_input(union event *ev)
48 {
49         static int special;
50
51         if(have_input()) {
52                 ev->type = EV_KEY;
53                 if((ev->key.key = getch()) == 0) {
54                         special = 1;
55                         return 0;
56                 }
57
58                 if(special) {
59                         special = 0;
60                         if((ev->key.key = conv_special(ev->key.key)) == -1) {
61                                 return 0;
62                         }
63                 } else {
64                         if(ev->key.key == '\r') {
65                                 ev->key.key = '\n';
66                         }
67                 }
68                 return 1;
69         }
70         return 0;
71 }
72
73 int have_input(void)
74 {
75         return kbhit();
76 }