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
30 #include "input/input.h"
34 // HACK, stdin is used as something else below
37 int mp_input_slave_cmd_func(int fd
,char* dest
,int size
){
39 HANDLE stdin
= GetStdHandle(STD_INPUT_HANDLE
);
40 if(!PeekNamedPipe(stdin
, NULL
, size
, &retval
, NULL
, NULL
) || !retval
){
41 return MP_INPUT_NOTHING
;
43 if(retval
>size
)retval
=size
;
44 ReadFile(stdin
, dest
, retval
, &retval
, NULL
);
45 if(retval
)return retval
;
46 return MP_INPUT_NOTHING
;
51 char * erase_to_end_of_line
= NULL
;
53 void get_screen_size(void){
57 static int getch2_status
=0;
59 static int getch2_internal(void)
61 INPUT_RECORD eventbuffer
[128];
64 if(!getch2_status
)return -1;
65 /*check if there are input events*/
66 if(!GetNumberOfConsoleInputEvents(stdin
,&retval
))
68 printf("getch2: can't get number of input events: %i\n",GetLastError());
71 if(retval
<=0)return -1;
74 if(!ReadConsoleInput(stdin
,eventbuffer
,128,&retval
))
76 printf("getch: can't read input events\n");
80 /*filter out keyevents*/
81 for (i
= 0; i
< retval
; i
++)
83 switch(eventbuffer
[i
].EventType
)
86 /*only a pressed key is interresting for us*/
87 if(eventbuffer
[i
].Event
.KeyEvent
.bKeyDown
== TRUE
)
89 /*check for special keys*/
90 switch(eventbuffer
[i
].Event
.KeyEvent
.wVirtualKeyCode
)
121 /*check for function keys*/
122 if(0x87 >= eventbuffer
[i
].Event
.KeyEvent
.wVirtualKeyCode
&& eventbuffer
[i
].Event
.KeyEvent
.wVirtualKeyCode
>= 0x70)
123 return KEY_F
+ 1 + eventbuffer
[i
].Event
.KeyEvent
.wVirtualKeyCode
- 0x70;
125 /*only characters should be remaining*/
126 //printf("getch2: YOU PRESSED \"%c\" \n",eventbuffer[i].Event.KeyEvent.uChar.AsciiChar);
127 return eventbuffer
[i
].Event
.KeyEvent
.uChar
.AsciiChar
;
132 case WINDOW_BUFFER_SIZE_EVENT
:
136 //printf("getch2: unsupported event type");
143 void getch2(struct mp_fifo
*fifo
)
145 int r
= getch2_internal();
147 mplayer_put_key(fifo
, r
);
150 void getch2_enable(void)
153 stdin
= GetStdHandle(STD_INPUT_HANDLE
);
154 if(!GetNumberOfConsoleInputEvents(stdin
,&retval
))
156 printf("getch2: %i can't get number of input events [disabling console input]\n",GetLastError());
159 else getch2_status
=1;
162 void getch2_disable(void)
164 if(!getch2_status
) return; // already disabled / never enabled
169 static const struct {
175 { 21866, "KOI8-RU" },
176 { 28591, "ISO-8859-1" },
177 { 28592, "ISO-8859-2" },
178 { 28593, "ISO-8859-3" },
179 { 28594, "ISO-8859-4" },
180 { 28595, "ISO-8859-5" },
181 { 28596, "ISO-8859-6" },
182 { 28597, "ISO-8859-7" },
183 { 28598, "ISO-8859-8" },
184 { 28599, "ISO-8859-9" },
185 { 28605, "ISO-8859-15" },
190 char* get_term_charset(void)
192 static char codepage
[10];
193 unsigned i
, cpno
= GetConsoleOutputCP();
199 for (i
= 0; cp_alias
[i
].cp
; i
++)
200 if (cpno
== cp_alias
[i
].cp
)
201 return cp_alias
[i
].alias
;
203 snprintf(codepage
, sizeof(codepage
), "CP%u", cpno
);