Mercurial > mplayer.hg
annotate osdep/getch2-win.c @ 16193:9001f47f4493
Synced with 1.178
author | jheryan |
---|---|
date | Wed, 10 Aug 2005 04:44:12 +0000 |
parents | 00a4cf87e2ff |
children | 08cac43f1e38 |
rev | line source |
---|---|
9766 | 1 /* windows TermIO for MPlayer (C) 2003 Sascha Sommer */ |
2 | |
3 // See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/VirtualKeyCodes.asp | |
4 // for additional virtual keycodes | |
5 | |
6 | |
7 #include <windows.h> | |
8 #include "keycodes.h" | |
10928 | 9 #include "../input/input.h" |
10 | |
11 int mp_input_win32_slave_cmd_func(int fd,char* dest,int size){ | |
13015
00a4cf87e2ff
fix slave mode for mingw, patch by Anton Ragnarsson <anton.ragnarsson.1093 at student.uu.se> some cleanup by be
faust3
parents:
10928
diff
changeset
|
12 DWORD retval; |
10928 | 13 HANDLE stdin = GetStdHandle(STD_INPUT_HANDLE); |
13015
00a4cf87e2ff
fix slave mode for mingw, patch by Anton Ragnarsson <anton.ragnarsson.1093 at student.uu.se> some cleanup by be
faust3
parents:
10928
diff
changeset
|
14 if(!PeekNamedPipe(stdin, NULL, size, &retval, NULL, NULL) || !retval){ |
00a4cf87e2ff
fix slave mode for mingw, patch by Anton Ragnarsson <anton.ragnarsson.1093 at student.uu.se> some cleanup by be
faust3
parents:
10928
diff
changeset
|
15 return MP_INPUT_NOTHING; |
10928 | 16 } |
13015
00a4cf87e2ff
fix slave mode for mingw, patch by Anton Ragnarsson <anton.ragnarsson.1093 at student.uu.se> some cleanup by be
faust3
parents:
10928
diff
changeset
|
17 if(retval>size)retval=size; |
00a4cf87e2ff
fix slave mode for mingw, patch by Anton Ragnarsson <anton.ragnarsson.1093 at student.uu.se> some cleanup by be
faust3
parents:
10928
diff
changeset
|
18 ReadFile(stdin, dest, retval, &retval, NULL); |
00a4cf87e2ff
fix slave mode for mingw, patch by Anton Ragnarsson <anton.ragnarsson.1093 at student.uu.se> some cleanup by be
faust3
parents:
10928
diff
changeset
|
19 if(retval)return retval; |
10928 | 20 return MP_INPUT_NOTHING; |
21 } | |
9766 | 22 |
23 int screen_width=80; | |
24 int screen_height=24; | |
25 | |
26 void get_screen_size(){ | |
27 } | |
28 | |
29 static HANDLE stdin; | |
9936
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
30 static int getch2_status=0; |
9766 | 31 |
32 int getch2(int time){ | |
33 INPUT_RECORD eventbuffer[128]; | |
34 DWORD retval; | |
35 int i=0; | |
9936
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
36 if(!getch2_status)return -1; |
9766 | 37 /*check if there are input events*/ |
38 if(!GetNumberOfConsoleInputEvents(stdin,&retval)) | |
39 { | |
40 printf("getch2: can't get number of input events: %i\n",GetLastError()); | |
41 return -1; | |
42 } | |
43 if(retval<=0)return -1; | |
44 | |
45 /*read all events*/ | |
46 if(!ReadConsoleInput(stdin,eventbuffer,128,&retval)) | |
47 { | |
48 printf("getch: can't read input events\n"); | |
49 return -1; | |
50 } | |
51 | |
52 /*filter out keyevents*/ | |
53 for (i = 0; i < retval; i++) | |
54 { | |
55 switch(eventbuffer[i].EventType) | |
56 { | |
57 case KEY_EVENT: | |
58 /*only a pressed key is interresting for us*/ | |
59 if(eventbuffer[i].Event.KeyEvent.bKeyDown == TRUE) | |
60 { | |
61 /*check for special keys*/ | |
62 switch(eventbuffer[i].Event.KeyEvent.wVirtualKeyCode) | |
63 { | |
64 case VK_HOME: | |
65 return KEY_HOME; | |
66 case VK_END: | |
67 return KEY_END; | |
68 case VK_DELETE: | |
69 return KEY_DEL; | |
70 case VK_INSERT: | |
71 return KEY_INS; | |
72 case VK_BACK: | |
73 return KEY_BS; | |
74 case VK_PRIOR: | |
75 return KEY_PGUP; | |
76 case VK_NEXT: | |
77 return KEY_PGDWN; | |
78 case VK_RETURN: | |
79 return KEY_ENTER; | |
80 case VK_ESCAPE: | |
81 return KEY_ESC; | |
82 case VK_LEFT: | |
83 return KEY_LEFT; | |
84 case VK_UP: | |
85 return KEY_UP; | |
86 case VK_RIGHT: | |
87 return KEY_RIGHT; | |
88 case VK_DOWN: | |
89 return KEY_DOWN; | |
10230 | 90 case VK_SHIFT: |
91 continue; | |
9766 | 92 } |
93 /*check for function keys*/ | |
10230 | 94 if(0x87 >= eventbuffer[i].Event.KeyEvent.wVirtualKeyCode >= 0x70) |
9766 | 95 return (KEY_F + 1 + eventbuffer[i].Event.KeyEvent.wVirtualKeyCode - 0x70); |
96 | |
97 /*only characters should be remaining*/ | |
98 //printf("getch2: YOU PRESSED \"%c\" \n",eventbuffer[i].Event.KeyEvent.uChar.AsciiChar); | |
99 return eventbuffer[i].Event.KeyEvent.uChar.AsciiChar; | |
100 } | |
101 break; | |
102 | |
103 case MOUSE_EVENT: | |
104 case WINDOW_BUFFER_SIZE_EVENT: | |
105 case FOCUS_EVENT: | |
106 case MENU_EVENT: | |
107 default: | |
108 //printf("getch2: unsupported event type"); | |
109 break; | |
110 } | |
111 } | |
112 return -1; | |
113 } | |
114 | |
115 | |
116 void getch2_enable(){ | |
9983
14c92818ab75
alternative timer and glob emulation code for mingw32 port
faust3
parents:
9936
diff
changeset
|
117 DWORD retval; |
9936
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
118 stdin = GetStdHandle(STD_INPUT_HANDLE); |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
119 if(!GetNumberOfConsoleInputEvents(stdin,&retval)) |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
120 { |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
121 printf("getch2: %i can't get number of input events [disabling console input]\n",GetLastError()); |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
122 getch2_status = 0; |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
123 } |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
124 else getch2_status=1; |
9766 | 125 } |
126 | |
127 void getch2_disable(){ | |
128 if(!getch2_status) return; // already disabled / never enabled | |
129 getch2_status=0; | |
130 } | |
131 |