Move direct-rendering hack from vo_xvmc to vf_vo, so it does not need to
[mplayer/glamo.git] / osdep / getch2-win.c
blob70608ea36640f2c4f64a66cb53a1e70c48f72b90
1 /* windows TermIO for MPlayer (C) 2003 Sascha Sommer */
3 // See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/VirtualKeyCodes.asp
4 // for additional virtual keycodes
7 #include "config.h"
8 #include <stdio.h>
9 #include <windows.h>
10 #include "keycodes.h"
11 #include "input/input.h"
12 #include "mp_fifo.h"
13 // HACK, stdin is used as something else below
14 #undef stdin
16 int mp_input_slave_cmd_func(int fd,char* dest,int size){
17 DWORD retval;
18 HANDLE stdin = GetStdHandle(STD_INPUT_HANDLE);
19 if(!PeekNamedPipe(stdin, NULL, size, &retval, NULL, NULL) || !retval){
20 return MP_INPUT_NOTHING;
22 if(retval>size)retval=size;
23 ReadFile(stdin, dest, retval, &retval, NULL);
24 if(retval)return retval;
25 return MP_INPUT_NOTHING;
28 int screen_width=80;
29 int screen_height=24;
30 char * erase_to_end_of_line = NULL;
32 void get_screen_size(void){
35 static HANDLE stdin;
36 static int getch2_status=0;
38 static int getch2_internal(void)
40 INPUT_RECORD eventbuffer[128];
41 DWORD retval;
42 int i=0;
43 if(!getch2_status)return -1;
44 /*check if there are input events*/
45 if(!GetNumberOfConsoleInputEvents(stdin,&retval))
47 printf("getch2: can't get number of input events: %i\n",GetLastError());
48 return -1;
50 if(retval<=0)return -1;
52 /*read all events*/
53 if(!ReadConsoleInput(stdin,eventbuffer,128,&retval))
55 printf("getch: can't read input events\n");
56 return -1;
59 /*filter out keyevents*/
60 for (i = 0; i < retval; i++)
62 switch(eventbuffer[i].EventType)
64 case KEY_EVENT:
65 /*only a pressed key is interresting for us*/
66 if(eventbuffer[i].Event.KeyEvent.bKeyDown == TRUE)
68 /*check for special keys*/
69 switch(eventbuffer[i].Event.KeyEvent.wVirtualKeyCode)
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;
97 case VK_SHIFT:
98 continue;
100 /*check for function keys*/
101 if(0x87 >= eventbuffer[i].Event.KeyEvent.wVirtualKeyCode && eventbuffer[i].Event.KeyEvent.wVirtualKeyCode >= 0x70)
102 return KEY_F + 1 + eventbuffer[i].Event.KeyEvent.wVirtualKeyCode - 0x70;
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;
108 break;
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;
119 return -1;
122 void getch2(void)
124 int r = getch2_internal();
125 if (r >= 0)
126 mplayer_put_key(r);
129 void getch2_enable(void)
131 DWORD retval;
132 stdin = GetStdHandle(STD_INPUT_HANDLE);
133 if(!GetNumberOfConsoleInputEvents(stdin,&retval))
135 printf("getch2: %i can't get number of input events [disabling console input]\n",GetLastError());
136 getch2_status = 0;
138 else getch2_status=1;
141 void getch2_disable(void)
143 if(!getch2_status) return; // already disabled / never enabled
144 getch2_status=0;
147 #ifdef CONFIG_ICONV
148 static const struct {
149 unsigned cp;
150 char* alias;
151 } cp_alias[] = {
152 { 20127, "ASCII" },
153 { 20866, "KOI8-R" },
154 { 21866, "KOI8-RU" },
155 { 28591, "ISO-8859-1" },
156 { 28592, "ISO-8859-2" },
157 { 28593, "ISO-8859-3" },
158 { 28594, "ISO-8859-4" },
159 { 28595, "ISO-8859-5" },
160 { 28596, "ISO-8859-6" },
161 { 28597, "ISO-8859-7" },
162 { 28598, "ISO-8859-8" },
163 { 28599, "ISO-8859-9" },
164 { 28605, "ISO-8859-15" },
165 { 65001, "UTF-8" },
166 { 0, NULL }
169 char* get_term_charset(void)
171 static char codepage[10];
172 unsigned i, cpno = GetConsoleOutputCP();
173 if (!cpno)
174 cpno = GetACP();
175 if (!cpno)
176 return NULL;
178 for (i = 0; cp_alias[i].cp; i++)
179 if (cpno == cp_alias[i].cp)
180 return cp_alias[i].alias;
182 snprintf(codepage, sizeof(codepage), "CP%u", cpno);
183 return codepage;
185 #endif