Add P4 Northwood. (Roman Shiryaev <mih_val@mail.ru>; See <200308250434.38516.mih_val...
[mplayer/greg.git] / osdep / getch2-win.c
blob59fd751c9973c2e0be35edf8ac138f638bc44176
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
7 #include <windows.h>
8 #include "keycodes.h"
10 int screen_width=80;
11 int screen_height=24;
13 void get_screen_size(){
16 static HANDLE stdin;
17 static int getch2_status=0;
19 int getch2(int time){
20 INPUT_RECORD eventbuffer[128];
21 DWORD retval;
22 int i=0;
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());
28 return -1;
30 if(retval<=0)return -1;
32 /*read all events*/
33 if(!ReadConsoleInput(stdin,eventbuffer,128,&retval))
35 printf("getch: can't read input events\n");
36 return -1;
39 /*filter out keyevents*/
40 for (i = 0; i < retval; i++)
42 switch(eventbuffer[i].EventType)
44 case KEY_EVENT:
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)
51 case VK_HOME:
52 return KEY_HOME;
53 case VK_END:
54 return KEY_END;
55 case VK_DELETE:
56 return KEY_DEL;
57 case VK_INSERT:
58 return KEY_INS;
59 case VK_BACK:
60 return KEY_BS;
61 case VK_PRIOR:
62 return KEY_PGUP;
63 case VK_NEXT:
64 return KEY_PGDWN;
65 case VK_RETURN:
66 return KEY_ENTER;
67 case VK_ESCAPE:
68 return KEY_ESC;
69 case VK_LEFT:
70 return KEY_LEFT;
71 case VK_UP:
72 return KEY_UP;
73 case VK_RIGHT:
74 return KEY_RIGHT;
75 case VK_DOWN:
76 return KEY_DOWN;
77 case VK_SHIFT:
78 continue;
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;
88 break;
90 case MOUSE_EVENT:
91 case WINDOW_BUFFER_SIZE_EVENT:
92 case FOCUS_EVENT:
93 case MENU_EVENT:
94 default:
95 //printf("getch2: unsupported event type");
96 break;
99 return -1;
103 void getch2_enable(){
104 DWORD retval;
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());
109 getch2_status = 0;
111 else getch2_status=1;
114 void getch2_disable(){
115 if(!getch2_status) return; // already disabled / never enabled
116 getch2_status=0;