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
11 #include "input/input.h"
15 // HACK, stdin is used as something else below
18 int mp_input_slave_cmd_func(int fd
,char* dest
,int size
){
20 HANDLE stdin
= GetStdHandle(STD_INPUT_HANDLE
);
21 if(!PeekNamedPipe(stdin
, NULL
, size
, &retval
, NULL
, NULL
) || !retval
){
22 return MP_INPUT_NOTHING
;
24 if(retval
>size
)retval
=size
;
25 ReadFile(stdin
, dest
, retval
, &retval
, NULL
);
26 if(retval
)return retval
;
27 return MP_INPUT_NOTHING
;
32 char * erase_to_end_of_line
= NULL
;
34 void get_screen_size(){
38 static int getch2_status
=0;
40 static int getch2_internal(void)
42 INPUT_RECORD eventbuffer
[128];
45 if(!getch2_status
)return -1;
46 /*check if there are input events*/
47 if(!GetNumberOfConsoleInputEvents(stdin
,&retval
))
49 printf("getch2: can't get number of input events: %i\n",GetLastError());
52 if(retval
<=0)return -1;
55 if(!ReadConsoleInput(stdin
,eventbuffer
,128,&retval
))
57 printf("getch: can't read input events\n");
61 /*filter out keyevents*/
62 for (i
= 0; i
< retval
; i
++)
64 switch(eventbuffer
[i
].EventType
)
67 /*only a pressed key is interresting for us*/
68 if(eventbuffer
[i
].Event
.KeyEvent
.bKeyDown
== TRUE
)
70 /*check for special keys*/
71 switch(eventbuffer
[i
].Event
.KeyEvent
.wVirtualKeyCode
)
102 /*check for function keys*/
103 if(0x87 >= eventbuffer
[i
].Event
.KeyEvent
.wVirtualKeyCode
&& eventbuffer
[i
].Event
.KeyEvent
.wVirtualKeyCode
>= 0x70)
104 return KEY_F
+ 1 + eventbuffer
[i
].Event
.KeyEvent
.wVirtualKeyCode
- 0x70;
106 /*only characters should be remaining*/
107 //printf("getch2: YOU PRESSED \"%c\" \n",eventbuffer[i].Event.KeyEvent.uChar.AsciiChar);
108 return eventbuffer
[i
].Event
.KeyEvent
.uChar
.AsciiChar
;
113 case WINDOW_BUFFER_SIZE_EVENT
:
117 //printf("getch2: unsupported event type");
124 void getch2(struct mp_fifo
*fifo
)
126 int r
= getch2_internal();
128 mplayer_put_key(fifo
, r
);
131 void getch2_enable(){
133 stdin
= GetStdHandle(STD_INPUT_HANDLE
);
134 if(!GetNumberOfConsoleInputEvents(stdin
,&retval
))
136 printf("getch2: %i can't get number of input events [disabling console input]\n",GetLastError());
139 else getch2_status
=1;
142 void getch2_disable(){
143 if(!getch2_status
) return; // already disabled / never enabled
148 static const struct {
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" },
169 char* get_term_charset(void)
171 static char codepage
[10];
172 unsigned i
, cpno
= GetConsoleOutputCP();
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
);