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
13 void get_screen_size(){
17 static int getch2_status
=0;
20 INPUT_RECORD eventbuffer
[128];
23 if(!getch2_status
)return -1;
24 /*check if there are input events*/
25 if(!GetNumberOfConsoleInputEvents(stdin
,&retval
))
27 printf("getch2: can't get number of input events: %i\n",GetLastError());
30 if(retval
<=0)return -1;
33 if(!ReadConsoleInput(stdin
,eventbuffer
,128,&retval
))
35 printf("getch: can't read input events\n");
39 /*filter out keyevents*/
40 for (i
= 0; i
< retval
; i
++)
42 switch(eventbuffer
[i
].EventType
)
45 /*only a pressed key is interresting for us*/
46 if(eventbuffer
[i
].Event
.KeyEvent
.bKeyDown
== TRUE
)
48 /*check for special keys*/
49 switch(eventbuffer
[i
].Event
.KeyEvent
.wVirtualKeyCode
)
80 /*check for function keys*/
81 if(0x87 >= eventbuffer
[i
].Event
.KeyEvent
.wVirtualKeyCode
>= 0x70)
82 return (KEY_F
+ 1 + eventbuffer
[i
].Event
.KeyEvent
.wVirtualKeyCode
- 0x70);
84 /*only characters should be remaining*/
85 //printf("getch2: YOU PRESSED \"%c\" \n",eventbuffer[i].Event.KeyEvent.uChar.AsciiChar);
86 return eventbuffer
[i
].Event
.KeyEvent
.uChar
.AsciiChar
;
91 case WINDOW_BUFFER_SIZE_EVENT
:
95 //printf("getch2: unsupported event type");
103 void getch2_enable(){
105 stdin
= GetStdHandle(STD_INPUT_HANDLE
);
106 if(!GetNumberOfConsoleInputEvents(stdin
,&retval
))
108 printf("getch2: %i can't get number of input events [disabling console input]\n",GetLastError());
111 else getch2_status
=1;
114 void getch2_disable(){
115 if(!getch2_status
) return; // already disabled / never enabled