Mercurial > mplayer.hg
annotate osdep/getch2-win.c @ 28873:4edc04d82a47
Remove now unused parts of nuppelvideo.h
author | reimar |
---|---|
date | Mon, 09 Mar 2009 13:23:27 +0000 |
parents | 5cfef41a1771 |
children | 0f1b5b68af32 |
rev | line source |
---|---|
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
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
26 #include "config.h" |
22441 | 27 #include <stdio.h> |
9766 | 28 #include <windows.h> |
29 #include "keycodes.h" | |
16985 | 30 #include "input/input.h" |
24129 | 31 #include "mp_fifo.h" |
22441 | 32 // HACK, stdin is used as something else below |
33 #undef stdin | |
10928 | 34 |
26015
f222f84f2072
Rename mp_input_win32_slave_cmd_func to mp_input_slave_cmd_func.
diego
parents:
24129
diff
changeset
|
35 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
parents:
10928
diff
changeset
|
36 DWORD retval; |
10928 | 37 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
parents:
10928
diff
changeset
|
38 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
parents:
10928
diff
changeset
|
39 return MP_INPUT_NOTHING; |
10928 | 40 } |
13015
00a4cf87e2ff
fix slave mode for mingw, patch by Anton Ragnarsson <anton.ragnarsson.1093 at student.uu.se> some cleanup by be
faust3
parents:
10928
diff
changeset
|
41 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
parents:
10928
diff
changeset
|
42 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
parents:
10928
diff
changeset
|
43 if(retval)return retval; |
10928 | 44 return MP_INPUT_NOTHING; |
45 } | |
9766 | 46 |
47 int screen_width=80; | |
48 int screen_height=24; | |
17258
3d02f6e2a432
change erase to end of line, fall back to old behavior if no termcap found
ods15
parents:
17251
diff
changeset
|
49 char * erase_to_end_of_line = NULL; |
9766 | 50 |
28232
8df85ad26746
Add missing 'void' keyword to parameterless function declarations.
diego
parents:
27393
diff
changeset
|
51 void get_screen_size(void){ |
9766 | 52 } |
53 | |
54 static HANDLE stdin; | |
9936
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
55 static int getch2_status=0; |
9766 | 56 |
24129 | 57 static int getch2_internal(void) |
58 { | |
9766 | 59 INPUT_RECORD eventbuffer[128]; |
60 DWORD retval; | |
61 int i=0; | |
9936
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
62 if(!getch2_status)return -1; |
9766 | 63 /*check if there are input events*/ |
64 if(!GetNumberOfConsoleInputEvents(stdin,&retval)) | |
65 { | |
66 printf("getch2: can't get number of input events: %i\n",GetLastError()); | |
67 return -1; | |
68 } | |
69 if(retval<=0)return -1; | |
70 | |
71 /*read all events*/ | |
72 if(!ReadConsoleInput(stdin,eventbuffer,128,&retval)) | |
73 { | |
74 printf("getch: can't read input events\n"); | |
75 return -1; | |
76 } | |
77 | |
78 /*filter out keyevents*/ | |
79 for (i = 0; i < retval; i++) | |
80 { | |
81 switch(eventbuffer[i].EventType) | |
82 { | |
83 case KEY_EVENT: | |
84 /*only a pressed key is interresting for us*/ | |
85 if(eventbuffer[i].Event.KeyEvent.bKeyDown == TRUE) | |
86 { | |
87 /*check for special keys*/ | |
88 switch(eventbuffer[i].Event.KeyEvent.wVirtualKeyCode) | |
89 { | |
90 case VK_HOME: | |
91 return KEY_HOME; | |
92 case VK_END: | |
93 return KEY_END; | |
94 case VK_DELETE: | |
95 return KEY_DEL; | |
96 case VK_INSERT: | |
97 return KEY_INS; | |
98 case VK_BACK: | |
99 return KEY_BS; | |
100 case VK_PRIOR: | |
101 return KEY_PGUP; | |
102 case VK_NEXT: | |
103 return KEY_PGDWN; | |
104 case VK_RETURN: | |
105 return KEY_ENTER; | |
106 case VK_ESCAPE: | |
107 return KEY_ESC; | |
108 case VK_LEFT: | |
109 return KEY_LEFT; | |
110 case VK_UP: | |
111 return KEY_UP; | |
112 case VK_RIGHT: | |
113 return KEY_RIGHT; | |
114 case VK_DOWN: | |
115 return KEY_DOWN; | |
10230 | 116 case VK_SHIFT: |
117 continue; | |
9766 | 118 } |
119 /*check for function keys*/ | |
18107
24003616a623
10l, fix broken if (X >= Y >= Z) comparison, probably stopped F-keys from working
reimar
parents:
18070
diff
changeset
|
120 if(0x87 >= eventbuffer[i].Event.KeyEvent.wVirtualKeyCode && eventbuffer[i].Event.KeyEvent.wVirtualKeyCode >= 0x70) |
26759
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
26015
diff
changeset
|
121 return KEY_F + 1 + eventbuffer[i].Event.KeyEvent.wVirtualKeyCode - 0x70; |
9766 | 122 |
123 /*only characters should be remaining*/ | |
124 //printf("getch2: YOU PRESSED \"%c\" \n",eventbuffer[i].Event.KeyEvent.uChar.AsciiChar); | |
125 return eventbuffer[i].Event.KeyEvent.uChar.AsciiChar; | |
126 } | |
127 break; | |
128 | |
129 case MOUSE_EVENT: | |
130 case WINDOW_BUFFER_SIZE_EVENT: | |
131 case FOCUS_EVENT: | |
132 case MENU_EVENT: | |
133 default: | |
134 //printf("getch2: unsupported event type"); | |
135 break; | |
136 } | |
137 } | |
138 return -1; | |
139 } | |
140 | |
24129 | 141 void getch2(void) |
142 { | |
143 int r = getch2_internal(); | |
144 if (r >= 0) | |
145 mplayer_put_key(r); | |
146 } | |
9766 | 147 |
28232
8df85ad26746
Add missing 'void' keyword to parameterless function declarations.
diego
parents:
27393
diff
changeset
|
148 void getch2_enable(void) |
8df85ad26746
Add missing 'void' keyword to parameterless function declarations.
diego
parents:
27393
diff
changeset
|
149 { |
9983
14c92818ab75
alternative timer and glob emulation code for mingw32 port
faust3
parents:
9936
diff
changeset
|
150 DWORD retval; |
9936
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
151 stdin = GetStdHandle(STD_INPUT_HANDLE); |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
152 if(!GetNumberOfConsoleInputEvents(stdin,&retval)) |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
153 { |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
154 printf("getch2: %i can't get number of input events [disabling console input]\n",GetLastError()); |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
155 getch2_status = 0; |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
156 } |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
157 else getch2_status=1; |
9766 | 158 } |
159 | |
28232
8df85ad26746
Add missing 'void' keyword to parameterless function declarations.
diego
parents:
27393
diff
changeset
|
160 void getch2_disable(void) |
8df85ad26746
Add missing 'void' keyword to parameterless function declarations.
diego
parents:
27393
diff
changeset
|
161 { |
9766 | 162 if(!getch2_status) return; // already disabled / never enabled |
163 getch2_status=0; | |
164 } | |
165 | |
27393 | 166 #ifdef CONFIG_ICONV |
22442
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
167 static const struct { |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
168 unsigned cp; |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
169 char* alias; |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
170 } cp_alias[] = { |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
171 { 20127, "ASCII" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
172 { 20866, "KOI8-R" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
173 { 21866, "KOI8-RU" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
174 { 28591, "ISO-8859-1" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
175 { 28592, "ISO-8859-2" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
176 { 28593, "ISO-8859-3" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
177 { 28594, "ISO-8859-4" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
178 { 28595, "ISO-8859-5" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
179 { 28596, "ISO-8859-6" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
180 { 28597, "ISO-8859-7" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
181 { 28598, "ISO-8859-8" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
182 { 28599, "ISO-8859-9" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
183 { 28605, "ISO-8859-15" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
184 { 65001, "UTF-8" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
185 { 0, NULL } |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
186 }; |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
187 |
22886 | 188 char* get_term_charset(void) |
22442
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
189 { |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
190 static char codepage[10]; |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
191 unsigned i, cpno = GetConsoleOutputCP(); |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
192 if (!cpno) |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
193 cpno = GetACP(); |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
194 if (!cpno) |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
195 return NULL; |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
196 |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
197 for (i = 0; cp_alias[i].cp; i++) |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
198 if (cpno == cp_alias[i].cp) |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
199 return cp_alias[i].alias; |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
200 |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
201 snprintf(codepage, sizeof(codepage), "CP%u", cpno); |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
202 return codepage; |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
203 } |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
204 #endif |