28744
|
1 /* Windows TermIO
|
|
2 *
|
|
3 * copyright (C) 2003 Sascha Sommer
|
|
4 *
|
|
5 * This file is part of MPlayer.
|
|
6 *
|
|
7 * MPlayer is free software; you can redistribute it and/or modify
|
|
8 * it under the terms of the GNU General Public License as published by
|
|
9 * the Free Software Foundation; either version 2 of the License, or
|
|
10 * (at your option) any later version.
|
|
11 *
|
|
12 * MPlayer is distributed in the hope that it will be useful,
|
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 * GNU General Public License for more details.
|
|
16 *
|
|
17 * You should have received a copy of the GNU General Public License along
|
|
18 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 */
|
9766
|
21
|
|
22 // See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/VirtualKeyCodes.asp
|
|
23 // for additional virtual keycodes
|
|
24
|
|
25
|
22442
|
26 #include "config.h"
|
22441
|
27 #include <stdio.h>
|
29290
|
28 #include <string.h>
|
9766
|
29 #include <windows.h>
|
|
30 #include "keycodes.h"
|
16985
|
31 #include "input/input.h"
|
24129
|
32 #include "mp_fifo.h"
|
22441
|
33 // HACK, stdin is used as something else below
|
|
34 #undef stdin
|
10928
|
35
|
26015
|
36 int mp_input_slave_cmd_func(int fd,char* dest,int size){
|
13015
00a4cf87e2ff
fix slave mode for mingw, patch by Anton Ragnarsson <anton.ragnarsson.1093 at student.uu.se> some cleanup by be
faust3
diff
changeset
|
37 DWORD retval;
|
10928
|
38 HANDLE stdin = GetStdHandle(STD_INPUT_HANDLE);
|
13015
00a4cf87e2ff
fix slave mode for mingw, patch by Anton Ragnarsson <anton.ragnarsson.1093 at student.uu.se> some cleanup by be
faust3
diff
changeset
|
39 if(!PeekNamedPipe(stdin, NULL, size, &retval, NULL, NULL) || !retval){
|
00a4cf87e2ff
fix slave mode for mingw, patch by Anton Ragnarsson <anton.ragnarsson.1093 at student.uu.se> some cleanup by be
faust3
diff
changeset
|
40 return MP_INPUT_NOTHING;
|
10928
|
41 }
|
13015
00a4cf87e2ff
fix slave mode for mingw, patch by Anton Ragnarsson <anton.ragnarsson.1093 at student.uu.se> some cleanup by be
faust3
diff
changeset
|
42 if(retval>size)retval=size;
|
00a4cf87e2ff
fix slave mode for mingw, patch by Anton Ragnarsson <anton.ragnarsson.1093 at student.uu.se> some cleanup by be
faust3
diff
changeset
|
43 ReadFile(stdin, dest, retval, &retval, NULL);
|
00a4cf87e2ff
fix slave mode for mingw, patch by Anton Ragnarsson <anton.ragnarsson.1093 at student.uu.se> some cleanup by be
faust3
diff
changeset
|
44 if(retval)return retval;
|
10928
|
45 return MP_INPUT_NOTHING;
|
|
46 }
|
9766
|
47
|
|
48 int screen_width=80;
|
|
49 int screen_height=24;
|
17258
|
50 char * erase_to_end_of_line = NULL;
|
9766
|
51
|
28232
|
52 void get_screen_size(void){
|
9766
|
53 }
|
|
54
|
|
55 static HANDLE stdin;
|
9936
|
56 static int getch2_status=0;
|
9766
|
57
|
24129
|
58 static int getch2_internal(void)
|
|
59 {
|
9766
|
60 INPUT_RECORD eventbuffer[128];
|
|
61 DWORD retval;
|
|
62 int i=0;
|
29263
|
63 if(!getch2_status)return -1;
|
9766
|
64 /*check if there are input events*/
|
|
65 if(!GetNumberOfConsoleInputEvents(stdin,&retval))
|
|
66 {
|
|
67 printf("getch2: can't get number of input events: %i\n",GetLastError());
|
|
68 return -1;
|
|
69 }
|
|
70 if(retval<=0)return -1;
|
29263
|
71
|
|
72 /*read all events*/
|
9766
|
73 if(!ReadConsoleInput(stdin,eventbuffer,128,&retval))
|
|
74 {
|
|
75 printf("getch: can't read input events\n");
|
|
76 return -1;
|
|
77 }
|
29263
|
78
|
9766
|
79 /*filter out keyevents*/
|
29263
|
80 for (i = 0; i < retval; i++)
|
9766
|
81 {
|
29263
|
82 switch(eventbuffer[i].EventType)
|
9766
|
83 {
|
|
84 case KEY_EVENT:
|
|
85 /*only a pressed key is interresting for us*/
|
|
86 if(eventbuffer[i].Event.KeyEvent.bKeyDown == TRUE)
|
|
87 {
|
|
88 /*check for special keys*/
|
|
89 switch(eventbuffer[i].Event.KeyEvent.wVirtualKeyCode)
|
|
90 {
|
|
91 case VK_HOME:
|
|
92 return KEY_HOME;
|
|
93 case VK_END:
|
|
94 return KEY_END;
|
|
95 case VK_DELETE:
|
|
96 return KEY_DEL;
|
|
97 case VK_INSERT:
|
|
98 return KEY_INS;
|
|
99 case VK_BACK:
|
|
100 return KEY_BS;
|
|
101 case VK_PRIOR:
|
|
102 return KEY_PGUP;
|
|
103 case VK_NEXT:
|
|
104 return KEY_PGDWN;
|
|
105 case VK_RETURN:
|
|
106 return KEY_ENTER;
|
|
107 case VK_ESCAPE:
|
|
108 return KEY_ESC;
|
|
109 case VK_LEFT:
|
|
110 return KEY_LEFT;
|
|
111 case VK_UP:
|
|
112 return KEY_UP;
|
|
113 case VK_RIGHT:
|
|
114 return KEY_RIGHT;
|
|
115 case VK_DOWN:
|
|
116 return KEY_DOWN;
|
10230
|
117 case VK_SHIFT:
|
29263
|
118 continue;
|
9766
|
119 }
|
|
120 /*check for function keys*/
|
18107
|
121 if(0x87 >= eventbuffer[i].Event.KeyEvent.wVirtualKeyCode && eventbuffer[i].Event.KeyEvent.wVirtualKeyCode >= 0x70)
|
26759
|
122 return KEY_F + 1 + eventbuffer[i].Event.KeyEvent.wVirtualKeyCode - 0x70;
|
29263
|
123
|
9766
|
124 /*only characters should be remaining*/
|
29263
|
125 //printf("getch2: YOU PRESSED \"%c\" \n",eventbuffer[i].Event.KeyEvent.uChar.AsciiChar);
|
9766
|
126 return eventbuffer[i].Event.KeyEvent.uChar.AsciiChar;
|
|
127 }
|
29263
|
128 break;
|
|
129
|
9766
|
130 case MOUSE_EVENT:
|
29263
|
131 case WINDOW_BUFFER_SIZE_EVENT:
|
|
132 case FOCUS_EVENT:
|
9766
|
133 case MENU_EVENT:
|
|
134 default:
|
29263
|
135 //printf("getch2: unsupported event type");
|
|
136 break;
|
|
137 }
|
9766
|
138 }
|
|
139 return -1;
|
|
140 }
|
|
141
|
24129
|
142 void getch2(void)
|
|
143 {
|
|
144 int r = getch2_internal();
|
|
145 if (r >= 0)
|
|
146 mplayer_put_key(r);
|
|
147 }
|
9766
|
148
|
28232
|
149 void getch2_enable(void)
|
|
150 {
|
9983
|
151 DWORD retval;
|
9936
|
152 stdin = GetStdHandle(STD_INPUT_HANDLE);
|
|
153 if(!GetNumberOfConsoleInputEvents(stdin,&retval))
|
|
154 {
|
|
155 printf("getch2: %i can't get number of input events [disabling console input]\n",GetLastError());
|
|
156 getch2_status = 0;
|
|
157 }
|
|
158 else getch2_status=1;
|
9766
|
159 }
|
|
160
|
28232
|
161 void getch2_disable(void)
|
|
162 {
|
9766
|
163 if(!getch2_status) return; // already disabled / never enabled
|
|
164 getch2_status=0;
|
|
165 }
|
|
166
|
27393
|
167 #ifdef CONFIG_ICONV
|
22442
|
168 static const struct {
|
|
169 unsigned cp;
|
|
170 char* alias;
|
|
171 } cp_alias[] = {
|
|
172 { 20127, "ASCII" },
|
|
173 { 20866, "KOI8-R" },
|
|
174 { 21866, "KOI8-RU" },
|
|
175 { 28591, "ISO-8859-1" },
|
|
176 { 28592, "ISO-8859-2" },
|
|
177 { 28593, "ISO-8859-3" },
|
|
178 { 28594, "ISO-8859-4" },
|
|
179 { 28595, "ISO-8859-5" },
|
|
180 { 28596, "ISO-8859-6" },
|
|
181 { 28597, "ISO-8859-7" },
|
|
182 { 28598, "ISO-8859-8" },
|
|
183 { 28599, "ISO-8859-9" },
|
|
184 { 28605, "ISO-8859-15" },
|
|
185 { 65001, "UTF-8" },
|
|
186 { 0, NULL }
|
|
187 };
|
29263
|
188
|
22886
|
189 char* get_term_charset(void)
|
22442
|
190 {
|
29290
|
191 char codepage[10];
|
22442
|
192 unsigned i, cpno = GetConsoleOutputCP();
|
|
193 if (!cpno)
|
|
194 cpno = GetACP();
|
|
195 if (!cpno)
|
|
196 return NULL;
|
|
197
|
|
198 for (i = 0; cp_alias[i].cp; i++)
|
|
199 if (cpno == cp_alias[i].cp)
|
29290
|
200 return strdup(cp_alias[i].alias);
|
22442
|
201
|
|
202 snprintf(codepage, sizeof(codepage), "CP%u", cpno);
|
29290
|
203 return strdup(codepage);
|
22442
|
204 }
|
|
205 #endif
|