Mercurial > mplayer.hg
annotate osdep/getch2-win.c @ 23789:90d1da8c9f4c
better translation
author | ptt |
---|---|
date | Tue, 17 Jul 2007 16:50:46 +0000 |
parents | 71b3e04d0555 |
children | 50e1e79056b6 |
rev | line source |
---|---|
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 | |
22442
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
7 #include "config.h" |
22441 | 8 #include <stdio.h> |
9766 | 9 #include <windows.h> |
10 #include "keycodes.h" | |
16985 | 11 #include "input/input.h" |
22441 | 12 // HACK, stdin is used as something else below |
13 #undef stdin | |
10928 | 14 |
15 int mp_input_win32_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
|
16 DWORD retval; |
10928 | 17 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
|
18 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
|
19 return MP_INPUT_NOTHING; |
10928 | 20 } |
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
|
21 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
|
22 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
|
23 if(retval)return retval; |
10928 | 24 return MP_INPUT_NOTHING; |
25 } | |
9766 | 26 |
27 int screen_width=80; | |
28 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
|
29 char * erase_to_end_of_line = NULL; |
9766 | 30 |
31 void get_screen_size(){ | |
32 } | |
33 | |
34 static HANDLE stdin; | |
9936
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
35 static int getch2_status=0; |
9766 | 36 |
37 int getch2(int time){ | |
38 INPUT_RECORD eventbuffer[128]; | |
39 DWORD retval; | |
40 int i=0; | |
9936
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
41 if(!getch2_status)return -1; |
9766 | 42 /*check if there are input events*/ |
18070
c1e25c011c54
getch2 should wait for input. Fixes 100% CPU usage during cache fill.
reimar
parents:
17258
diff
changeset
|
43 WaitForSingleObject(stdin, time); |
9766 | 44 if(!GetNumberOfConsoleInputEvents(stdin,&retval)) |
45 { | |
46 printf("getch2: can't get number of input events: %i\n",GetLastError()); | |
47 return -1; | |
48 } | |
49 if(retval<=0)return -1; | |
50 | |
51 /*read all events*/ | |
52 if(!ReadConsoleInput(stdin,eventbuffer,128,&retval)) | |
53 { | |
54 printf("getch: can't read input events\n"); | |
55 return -1; | |
56 } | |
57 | |
58 /*filter out keyevents*/ | |
59 for (i = 0; i < retval; i++) | |
60 { | |
61 switch(eventbuffer[i].EventType) | |
62 { | |
63 case KEY_EVENT: | |
64 /*only a pressed key is interresting for us*/ | |
65 if(eventbuffer[i].Event.KeyEvent.bKeyDown == TRUE) | |
66 { | |
67 /*check for special keys*/ | |
68 switch(eventbuffer[i].Event.KeyEvent.wVirtualKeyCode) | |
69 { | |
70 case VK_HOME: | |
71 return KEY_HOME; | |
72 case VK_END: | |
73 return KEY_END; | |
74 case VK_DELETE: | |
75 return KEY_DEL; | |
76 case VK_INSERT: | |
77 return KEY_INS; | |
78 case VK_BACK: | |
79 return KEY_BS; | |
80 case VK_PRIOR: | |
81 return KEY_PGUP; | |
82 case VK_NEXT: | |
83 return KEY_PGDWN; | |
84 case VK_RETURN: | |
85 return KEY_ENTER; | |
86 case VK_ESCAPE: | |
87 return KEY_ESC; | |
88 case VK_LEFT: | |
89 return KEY_LEFT; | |
90 case VK_UP: | |
91 return KEY_UP; | |
92 case VK_RIGHT: | |
93 return KEY_RIGHT; | |
94 case VK_DOWN: | |
95 return KEY_DOWN; | |
10230 | 96 case VK_SHIFT: |
97 continue; | |
9766 | 98 } |
99 /*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
|
100 if(0x87 >= eventbuffer[i].Event.KeyEvent.wVirtualKeyCode && eventbuffer[i].Event.KeyEvent.wVirtualKeyCode >= 0x70) |
9766 | 101 return (KEY_F + 1 + eventbuffer[i].Event.KeyEvent.wVirtualKeyCode - 0x70); |
102 | |
103 /*only characters should be remaining*/ | |
104 //printf("getch2: YOU PRESSED \"%c\" \n",eventbuffer[i].Event.KeyEvent.uChar.AsciiChar); | |
105 return eventbuffer[i].Event.KeyEvent.uChar.AsciiChar; | |
106 } | |
107 break; | |
108 | |
109 case MOUSE_EVENT: | |
110 case WINDOW_BUFFER_SIZE_EVENT: | |
111 case FOCUS_EVENT: | |
112 case MENU_EVENT: | |
113 default: | |
114 //printf("getch2: unsupported event type"); | |
115 break; | |
116 } | |
117 } | |
118 return -1; | |
119 } | |
120 | |
121 | |
122 void getch2_enable(){ | |
9983
14c92818ab75
alternative timer and glob emulation code for mingw32 port
faust3
parents:
9936
diff
changeset
|
123 DWORD retval; |
9936
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
124 stdin = GetStdHandle(STD_INPUT_HANDLE); |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
125 if(!GetNumberOfConsoleInputEvents(stdin,&retval)) |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
126 { |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
127 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
|
128 getch2_status = 0; |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
129 } |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
130 else getch2_status=1; |
9766 | 131 } |
132 | |
133 void getch2_disable(){ | |
134 if(!getch2_status) return; // already disabled / never enabled | |
135 getch2_status=0; | |
136 } | |
137 | |
22442
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
138 #ifdef USE_ICONV |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
139 static const struct { |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
140 unsigned cp; |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
141 char* alias; |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
142 } cp_alias[] = { |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
143 { 20127, "ASCII" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
144 { 20866, "KOI8-R" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
145 { 21866, "KOI8-RU" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
146 { 28591, "ISO-8859-1" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
147 { 28592, "ISO-8859-2" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
148 { 28593, "ISO-8859-3" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
149 { 28594, "ISO-8859-4" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
150 { 28595, "ISO-8859-5" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
151 { 28596, "ISO-8859-6" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
152 { 28597, "ISO-8859-7" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
153 { 28598, "ISO-8859-8" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
154 { 28599, "ISO-8859-9" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
155 { 28605, "ISO-8859-15" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
156 { 65001, "UTF-8" }, |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
157 { 0, NULL } |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
158 }; |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
159 |
22886 | 160 char* get_term_charset(void) |
22442
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
161 { |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
162 static char codepage[10]; |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
163 unsigned i, cpno = GetConsoleOutputCP(); |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
164 if (!cpno) |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
165 cpno = GetACP(); |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
166 if (!cpno) |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
167 return NULL; |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
168 |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
169 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
|
170 if (cpno == cp_alias[i].cp) |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
171 return cp_alias[i].alias; |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
172 |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
173 snprintf(codepage, sizeof(codepage), "CP%u", cpno); |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
174 return codepage; |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
175 } |
56a0b0f8a66e
Add code to detect and convert to console codepage on Windows.
reimar
parents:
22441
diff
changeset
|
176 #endif |