9766
|
1 /* windows TermIO for MPlayer (C) 2003 Sascha Sommer */
|
|
2
|
|
3 // See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/VirtualKeyCodes.asp
|
|
4 // for additional virtual keycodes
|
|
5
|
|
6
|
|
7 #include <windows.h>
|
|
8 #include "keycodes.h"
|
|
9
|
|
10 int screen_width=80;
|
|
11 int screen_height=24;
|
|
12
|
|
13 void get_screen_size(){
|
|
14 }
|
|
15
|
|
16 static HANDLE stdin;
|
|
17
|
|
18 int getch2(int time){
|
|
19 INPUT_RECORD eventbuffer[128];
|
|
20 DWORD retval;
|
|
21 int i=0;
|
|
22 /*check if there are input events*/
|
|
23 if(!GetNumberOfConsoleInputEvents(stdin,&retval))
|
|
24 {
|
|
25 printf("getch2: can't get number of input events: %i\n",GetLastError());
|
|
26 return -1;
|
|
27 }
|
|
28 if(retval<=0)return -1;
|
|
29
|
|
30 /*read all events*/
|
|
31 if(!ReadConsoleInput(stdin,eventbuffer,128,&retval))
|
|
32 {
|
|
33 printf("getch: can't read input events\n");
|
|
34 return -1;
|
|
35 }
|
|
36
|
|
37 /*filter out keyevents*/
|
|
38 for (i = 0; i < retval; i++)
|
|
39 {
|
|
40 switch(eventbuffer[i].EventType)
|
|
41 {
|
|
42 case KEY_EVENT:
|
|
43 /*only a pressed key is interresting for us*/
|
|
44 if(eventbuffer[i].Event.KeyEvent.bKeyDown == TRUE)
|
|
45 {
|
|
46 /*check for special keys*/
|
|
47 switch(eventbuffer[i].Event.KeyEvent.wVirtualKeyCode)
|
|
48 {
|
|
49 case VK_HOME:
|
|
50 return KEY_HOME;
|
|
51 case VK_END:
|
|
52 return KEY_END;
|
|
53 case VK_DELETE:
|
|
54 return KEY_DEL;
|
|
55 case VK_INSERT:
|
|
56 return KEY_INS;
|
|
57 case VK_BACK:
|
|
58 return KEY_BS;
|
|
59 case VK_PRIOR:
|
|
60 return KEY_PGUP;
|
|
61 case VK_NEXT:
|
|
62 return KEY_PGDWN;
|
|
63 case VK_RETURN:
|
|
64 return KEY_ENTER;
|
|
65 case VK_ESCAPE:
|
|
66 return KEY_ESC;
|
|
67 case VK_LEFT:
|
|
68 return KEY_LEFT;
|
|
69 case VK_UP:
|
|
70 return KEY_UP;
|
|
71 case VK_RIGHT:
|
|
72 return KEY_RIGHT;
|
|
73 case VK_DOWN:
|
|
74 return KEY_DOWN;
|
|
75 }
|
|
76 /*check for function keys*/
|
|
77 if(eventbuffer[i].Event.KeyEvent.wVirtualKeyCode >= 0x70)
|
|
78 return (KEY_F + 1 + eventbuffer[i].Event.KeyEvent.wVirtualKeyCode - 0x70);
|
|
79
|
|
80 /*only characters should be remaining*/
|
|
81 //printf("getch2: YOU PRESSED \"%c\" \n",eventbuffer[i].Event.KeyEvent.uChar.AsciiChar);
|
|
82 return eventbuffer[i].Event.KeyEvent.uChar.AsciiChar;
|
|
83 }
|
|
84 break;
|
|
85
|
|
86 case MOUSE_EVENT:
|
|
87 case WINDOW_BUFFER_SIZE_EVENT:
|
|
88 case FOCUS_EVENT:
|
|
89 case MENU_EVENT:
|
|
90 default:
|
|
91 //printf("getch2: unsupported event type");
|
|
92 break;
|
|
93 }
|
|
94 }
|
|
95 return -1;
|
|
96 }
|
|
97
|
|
98 static int getch2_status=0;
|
|
99
|
|
100 void getch2_enable(){
|
|
101 stdin = GetStdHandle(STD_INPUT_HANDLE);
|
|
102 getch2_status=1;
|
|
103 }
|
|
104
|
|
105 void getch2_disable(){
|
|
106 if(!getch2_status) return; // already disabled / never enabled
|
|
107 getch2_status=0;
|
|
108 }
|
|
109
|