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
9 #include "input/input.h"
11 int mp_input_win32_slave_cmd_func(int fd
,char* dest
,int size
){
13 HANDLE stdin
= GetStdHandle(STD_INPUT_HANDLE
);
14 if(!PeekNamedPipe(stdin
, NULL
, size
, &retval
, NULL
, NULL
) || !retval
){
15 return MP_INPUT_NOTHING
;
17 if(retval
>size
)retval
=size
;
18 ReadFile(stdin
, dest
, retval
, &retval
, NULL
);
19 if(retval
)return retval
;
20 return MP_INPUT_NOTHING
;
25 char * erase_to_end_of_line
= NULL
;
27 void get_screen_size(){
31 static int getch2_status
=0;
34 INPUT_RECORD eventbuffer
[128];
37 if(!getch2_status
)return -1;
38 /*check if there are input events*/
39 WaitForSingleObject(stdin
, time
);
40 if(!GetNumberOfConsoleInputEvents(stdin
,&retval
))
42 printf("getch2: can't get number of input events: %i\n",GetLastError());
45 if(retval
<=0)return -1;
48 if(!ReadConsoleInput(stdin
,eventbuffer
,128,&retval
))
50 printf("getch: can't read input events\n");
54 /*filter out keyevents*/
55 for (i
= 0; i
< retval
; i
++)
57 switch(eventbuffer
[i
].EventType
)
60 /*only a pressed key is interresting for us*/
61 if(eventbuffer
[i
].Event
.KeyEvent
.bKeyDown
== TRUE
)
63 /*check for special keys*/
64 switch(eventbuffer
[i
].Event
.KeyEvent
.wVirtualKeyCode
)
95 /*check for function keys*/
96 if(0x87 >= eventbuffer
[i
].Event
.KeyEvent
.wVirtualKeyCode
&& eventbuffer
[i
].Event
.KeyEvent
.wVirtualKeyCode
>= 0x70)
97 return (KEY_F
+ 1 + eventbuffer
[i
].Event
.KeyEvent
.wVirtualKeyCode
- 0x70);
99 /*only characters should be remaining*/
100 //printf("getch2: YOU PRESSED \"%c\" \n",eventbuffer[i].Event.KeyEvent.uChar.AsciiChar);
101 return eventbuffer
[i
].Event
.KeyEvent
.uChar
.AsciiChar
;
106 case WINDOW_BUFFER_SIZE_EVENT
:
110 //printf("getch2: unsupported event type");
118 void getch2_enable(){
120 stdin
= GetStdHandle(STD_INPUT_HANDLE
);
121 if(!GetNumberOfConsoleInputEvents(stdin
,&retval
))
123 printf("getch2: %i can't get number of input events [disabling console input]\n",GetLastError());
126 else getch2_status
=1;
129 void getch2_disable(){
130 if(!getch2_status
) return; // already disabled / never enabled