10l: comparison of char* ptrs with string literals
[mplayer.git] / osdep / getch2-win.c
blob80e745f9efe116b413f6e8e9a2765726cedb315a
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"
9 #include "input/input.h"
11 int mp_input_win32_slave_cmd_func(int fd,char* dest,int size){
12 DWORD retval;
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;
23 int screen_width=80;
24 int screen_height=24;
25 char * erase_to_end_of_line = NULL;
27 void get_screen_size(){
30 static HANDLE stdin;
31 static int getch2_status=0;
33 int getch2(int time){
34 INPUT_RECORD eventbuffer[128];
35 DWORD retval;
36 int i=0;
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());
43 return -1;
45 if(retval<=0)return -1;
47 /*read all events*/
48 if(!ReadConsoleInput(stdin,eventbuffer,128,&retval))
50 printf("getch: can't read input events\n");
51 return -1;
54 /*filter out keyevents*/
55 for (i = 0; i < retval; i++)
57 switch(eventbuffer[i].EventType)
59 case KEY_EVENT:
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)
66 case VK_HOME:
67 return KEY_HOME;
68 case VK_END:
69 return KEY_END;
70 case VK_DELETE:
71 return KEY_DEL;
72 case VK_INSERT:
73 return KEY_INS;
74 case VK_BACK:
75 return KEY_BS;
76 case VK_PRIOR:
77 return KEY_PGUP;
78 case VK_NEXT:
79 return KEY_PGDWN;
80 case VK_RETURN:
81 return KEY_ENTER;
82 case VK_ESCAPE:
83 return KEY_ESC;
84 case VK_LEFT:
85 return KEY_LEFT;
86 case VK_UP:
87 return KEY_UP;
88 case VK_RIGHT:
89 return KEY_RIGHT;
90 case VK_DOWN:
91 return KEY_DOWN;
92 case VK_SHIFT:
93 continue;
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;
103 break;
105 case MOUSE_EVENT:
106 case WINDOW_BUFFER_SIZE_EVENT:
107 case FOCUS_EVENT:
108 case MENU_EVENT:
109 default:
110 //printf("getch2: unsupported event type");
111 break;
114 return -1;
118 void getch2_enable(){
119 DWORD retval;
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());
124 getch2_status = 0;
126 else getch2_status=1;
129 void getch2_disable(){
130 if(!getch2_status) return; // already disabled / never enabled
131 getch2_status=0;