Mercurial > mplayer.hg
comparison osdep/getch2-win.c @ 30735:783071763328
Do not misuse the stdin name.
author | reimar |
---|---|
date | Sat, 27 Feb 2010 21:50:59 +0000 |
parents | 749c87b2c3e2 |
children | 25622198a15a |
comparison
equal
deleted
inserted
replaced
30734:749c87b2c3e2 | 30735:783071763328 |
---|---|
29 #include <windows.h> | 29 #include <windows.h> |
30 #include "keycodes.h" | 30 #include "keycodes.h" |
31 #include "input/input.h" | 31 #include "input/input.h" |
32 #include "mp_fifo.h" | 32 #include "mp_fifo.h" |
33 #include "getch2.h" | 33 #include "getch2.h" |
34 // HACK, stdin is used as something else below | |
35 #undef stdin | |
36 | 34 |
37 int mp_input_slave_cmd_func(int fd,char* dest,int size){ | 35 int mp_input_slave_cmd_func(int fd,char* dest,int size){ |
38 DWORD retval; | 36 DWORD retval; |
39 HANDLE stdin = GetStdHandle(STD_INPUT_HANDLE); | 37 HANDLE in = GetStdHandle(STD_INPUT_HANDLE); |
40 if(!PeekNamedPipe(stdin, NULL, size, &retval, NULL, NULL) || !retval){ | 38 if(!PeekNamedPipe(in, NULL, size, &retval, NULL, NULL) || !retval){ |
41 return MP_INPUT_NOTHING; | 39 return MP_INPUT_NOTHING; |
42 } | 40 } |
43 if(retval>size)retval=size; | 41 if(retval>size)retval=size; |
44 ReadFile(stdin, dest, retval, &retval, NULL); | 42 ReadFile(in, dest, retval, &retval, NULL); |
45 if(retval)return retval; | 43 if(retval)return retval; |
46 return MP_INPUT_NOTHING; | 44 return MP_INPUT_NOTHING; |
47 } | 45 } |
48 | 46 |
49 int screen_width=80; | 47 int screen_width=80; |
51 char * erase_to_end_of_line = NULL; | 49 char * erase_to_end_of_line = NULL; |
52 | 50 |
53 void get_screen_size(void){ | 51 void get_screen_size(void){ |
54 } | 52 } |
55 | 53 |
56 static HANDLE stdin; | 54 static HANDLE in; |
57 static int getch2_status=0; | 55 static int getch2_status=0; |
58 | 56 |
59 static int getch2_internal(void) | 57 static int getch2_internal(void) |
60 { | 58 { |
61 INPUT_RECORD eventbuffer[128]; | 59 INPUT_RECORD eventbuffer[128]; |
62 DWORD retval; | 60 DWORD retval; |
63 int i=0; | 61 int i=0; |
64 if(!getch2_status)return -1; | 62 if(!getch2_status)return -1; |
65 /*check if there are input events*/ | 63 /*check if there are input events*/ |
66 if(!GetNumberOfConsoleInputEvents(stdin,&retval)) | 64 if(!GetNumberOfConsoleInputEvents(in,&retval)) |
67 { | 65 { |
68 printf("getch2: can't get number of input events: %i\n",GetLastError()); | 66 printf("getch2: can't get number of input events: %i\n",GetLastError()); |
69 return -1; | 67 return -1; |
70 } | 68 } |
71 if(retval<=0)return -1; | 69 if(retval<=0)return -1; |
72 | 70 |
73 /*read all events*/ | 71 /*read all events*/ |
74 if(!ReadConsoleInput(stdin,eventbuffer,128,&retval)) | 72 if(!ReadConsoleInput(in,eventbuffer,128,&retval)) |
75 { | 73 { |
76 printf("getch: can't read input events\n"); | 74 printf("getch: can't read input events\n"); |
77 return -1; | 75 return -1; |
78 } | 76 } |
79 | 77 |
148 } | 146 } |
149 | 147 |
150 void getch2_enable(void) | 148 void getch2_enable(void) |
151 { | 149 { |
152 DWORD retval; | 150 DWORD retval; |
153 stdin = GetStdHandle(STD_INPUT_HANDLE); | 151 in = GetStdHandle(STD_INPUT_HANDLE); |
154 if(!GetNumberOfConsoleInputEvents(stdin,&retval)) | 152 if(!GetNumberOfConsoleInputEvents(in,&retval)) |
155 { | 153 { |
156 printf("getch2: %i can't get number of input events [disabling console input]\n",GetLastError()); | 154 printf("getch2: %i can't get number of input events [disabling console input]\n",GetLastError()); |
157 getch2_status = 0; | 155 getch2_status = 0; |
158 } | 156 } |
159 else getch2_status=1; | 157 else getch2_status=1; |