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