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"
13 // HACK, stdin is used as something else below
16 int mp_input_win32_slave_cmd_func(int fd
,char* dest
,int size
){
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
;
30 char * erase_to_end_of_line
= NULL
;
32 void get_screen_size(){
36 static int getch2_status
=0;
38 static int getch2_internal(void)
40 INPUT_RECORD eventbuffer
[128];
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());
50 if(retval
<=0)return -1;
53 if(!ReadConsoleInput(stdin
,eventbuffer
,128,&retval
))
55 printf("getch: can't read input events\n");
59 /*filter out keyevents*/
60 for (i
= 0; i
< retval
; i
++)
62 switch(eventbuffer
[i
].EventType
)
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
)
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
;
111 case WINDOW_BUFFER_SIZE_EVENT
:
115 //printf("getch2: unsupported event type");
124 int r
= getch2_internal();
129 void getch2_enable(){
131 stdin
= GetStdHandle(STD_INPUT_HANDLE
);
132 if(!GetNumberOfConsoleInputEvents(stdin
,&retval
))
134 printf("getch2: %i can't get number of input events [disabling console input]\n",GetLastError());
137 else getch2_status
=1;
140 void getch2_disable(){
141 if(!getch2_status
) return; // already disabled / never enabled
146 static const struct {
152 { 21866, "KOI8-RU" },
153 { 28591, "ISO-8859-1" },
154 { 28592, "ISO-8859-2" },
155 { 28593, "ISO-8859-3" },
156 { 28594, "ISO-8859-4" },
157 { 28595, "ISO-8859-5" },
158 { 28596, "ISO-8859-6" },
159 { 28597, "ISO-8859-7" },
160 { 28598, "ISO-8859-8" },
161 { 28599, "ISO-8859-9" },
162 { 28605, "ISO-8859-15" },
167 char* get_term_charset(void)
169 static char codepage
[10];
170 unsigned i
, cpno
= GetConsoleOutputCP();
176 for (i
= 0; cp_alias
[i
].cp
; i
++)
177 if (cpno
== cp_alias
[i
].cp
)
178 return cp_alias
[i
].alias
;
180 snprintf(codepage
, sizeof(codepage
), "CP%u", cpno
);