3 * copyright (C) 2003 Sascha Sommer
5 * This file is part of MPlayer.
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.
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.
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.
22 // See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/VirtualKeyCodes.asp
23 // for additional virtual keycodes
32 #include "input/input.h"
36 int mp_input_slave_cmd_func(int fd
,char* dest
,int size
){
38 HANDLE in
= GetStdHandle(STD_INPUT_HANDLE
);
39 if(PeekNamedPipe(in
, NULL
, size
, &retval
, NULL
, NULL
)){
40 if (size
> retval
) size
= retval
;
42 if (WaitForSingleObject(in
, 0))
46 return MP_INPUT_NOTHING
;
48 ReadFile(in
, dest
, size
, &retval
, NULL
);
49 if(retval
)return retval
;
50 return MP_INPUT_NOTHING
;
55 char * erase_to_end_of_line
= NULL
;
57 void get_screen_size(void){
61 static int getch2_status
=0;
63 static int getch2_internal(void)
65 INPUT_RECORD eventbuffer
[128];
69 // supports e.g. MinGW xterm, unfortunately keys are only received after
72 if (!PeekNamedPipe(in
, NULL
, 1, &retval
, NULL
, NULL
) || !retval
)
74 ReadFile(in
, &c
, 1, &retval
, NULL
);
75 return retval
== 1 ? c
: -1;
77 /*check if there are input events*/
78 if(!GetNumberOfConsoleInputEvents(in
,&retval
))
80 printf("getch2: can't get number of input events: %i\n",GetLastError());
83 if(retval
<=0)return -1;
86 if(!ReadConsoleInput(in
,eventbuffer
,128,&retval
))
88 printf("getch: can't read input events\n");
92 /*filter out keyevents*/
93 for (i
= 0; i
< retval
; i
++)
95 switch(eventbuffer
[i
].EventType
)
98 /*only a pressed key is interresting for us*/
99 if(eventbuffer
[i
].Event
.KeyEvent
.bKeyDown
== TRUE
)
101 /*check for special keys*/
102 switch(eventbuffer
[i
].Event
.KeyEvent
.wVirtualKeyCode
)
133 /*check for function keys*/
134 if(0x87 >= eventbuffer
[i
].Event
.KeyEvent
.wVirtualKeyCode
&& eventbuffer
[i
].Event
.KeyEvent
.wVirtualKeyCode
>= 0x70)
135 return KEY_F
+ 1 + eventbuffer
[i
].Event
.KeyEvent
.wVirtualKeyCode
- 0x70;
137 /*only characters should be remaining*/
138 //printf("getch2: YOU PRESSED \"%c\" \n",eventbuffer[i].Event.KeyEvent.uChar.AsciiChar);
139 return eventbuffer
[i
].Event
.KeyEvent
.uChar
.AsciiChar
;
144 case WINDOW_BUFFER_SIZE_EVENT
:
148 //printf("getch2: unsupported event type");
155 void getch2(struct mp_fifo
*fifo
)
157 int r
= getch2_internal();
159 mplayer_put_key(fifo
, r
);
162 void getch2_enable(void)
165 in
= GetStdHandle(STD_INPUT_HANDLE
);
166 if(!GetNumberOfConsoleInputEvents(in
,&retval
))
168 printf("getch2: %i can't get number of input events [disabling console input]\n",GetLastError());
171 else getch2_status
=1;
174 void getch2_disable(void)
176 if(!getch2_status
) return; // already disabled / never enabled
181 static const struct {
187 { 21866, "KOI8-RU" },
188 { 28591, "ISO-8859-1" },
189 { 28592, "ISO-8859-2" },
190 { 28593, "ISO-8859-3" },
191 { 28594, "ISO-8859-4" },
192 { 28595, "ISO-8859-5" },
193 { 28596, "ISO-8859-6" },
194 { 28597, "ISO-8859-7" },
195 { 28598, "ISO-8859-8" },
196 { 28599, "ISO-8859-9" },
197 { 28605, "ISO-8859-15" },
202 char* get_term_charset(void)
205 unsigned i
, cpno
= GetConsoleOutputCP();
211 for (i
= 0; cp_alias
[i
].cp
; i
++)
212 if (cpno
== cp_alias
[i
].cp
)
213 return strdup(cp_alias
[i
].alias
);
215 snprintf(codepage
, sizeof(codepage
), "CP%u", cpno
);
216 return strdup(codepage
);