Mercurial > mplayer.hg
annotate osdep/getch2-win.c @ 11220:cf4339e05e73
updates
author | alex |
---|---|
date | Wed, 22 Oct 2003 16:43:29 +0000 |
parents | f2313bd91594 |
children | 00a4cf87e2ff |
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){ | |
12 DWORD i,retval; | |
13 int x=0; | |
14 HANDLE stdin = GetStdHandle(STD_INPUT_HANDLE); | |
15 INPUT_RECORD eventbuffer[250]; | |
16 if(!GetNumberOfConsoleInputEvents(stdin,&retval) || !retval)return MP_INPUT_NOTHING; | |
17 ReadConsoleInput(stdin,eventbuffer,250,&retval); | |
18 for(i = 0; i < retval; i++){ | |
19 if(eventbuffer[i].EventType==KEY_EVENT&&eventbuffer[i].Event.KeyEvent.bKeyDown== TRUE){ | |
20 if(eventbuffer[i].Event.KeyEvent.wVirtualKeyCode==VK_RETURN)dest[x]='\n'; | |
21 else dest[x]=eventbuffer[i].Event.KeyEvent.uChar.AsciiChar; | |
22 ++x; | |
23 } | |
24 } | |
25 if(x)return x; | |
26 return MP_INPUT_NOTHING; | |
27 } | |
9766 | 28 |
29 int screen_width=80; | |
30 int screen_height=24; | |
31 | |
32 void get_screen_size(){ | |
33 } | |
34 | |
35 static HANDLE stdin; | |
9936
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
36 static int getch2_status=0; |
9766 | 37 |
38 int getch2(int time){ | |
39 INPUT_RECORD eventbuffer[128]; | |
40 DWORD retval; | |
41 int i=0; | |
9936
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
42 if(!getch2_status)return -1; |
9766 | 43 /*check if there are input events*/ |
44 if(!GetNumberOfConsoleInputEvents(stdin,&retval)) | |
45 { | |
46 printf("getch2: can't get number of input events: %i\n",GetLastError()); | |
47 return -1; | |
48 } | |
49 if(retval<=0)return -1; | |
50 | |
51 /*read all events*/ | |
52 if(!ReadConsoleInput(stdin,eventbuffer,128,&retval)) | |
53 { | |
54 printf("getch: can't read input events\n"); | |
55 return -1; | |
56 } | |
57 | |
58 /*filter out keyevents*/ | |
59 for (i = 0; i < retval; i++) | |
60 { | |
61 switch(eventbuffer[i].EventType) | |
62 { | |
63 case KEY_EVENT: | |
64 /*only a pressed key is interresting for us*/ | |
65 if(eventbuffer[i].Event.KeyEvent.bKeyDown == TRUE) | |
66 { | |
67 /*check for special keys*/ | |
68 switch(eventbuffer[i].Event.KeyEvent.wVirtualKeyCode) | |
69 { | |
70 case VK_HOME: | |
71 return KEY_HOME; | |
72 case VK_END: | |
73 return KEY_END; | |
74 case VK_DELETE: | |
75 return KEY_DEL; | |
76 case VK_INSERT: | |
77 return KEY_INS; | |
78 case VK_BACK: | |
79 return KEY_BS; | |
80 case VK_PRIOR: | |
81 return KEY_PGUP; | |
82 case VK_NEXT: | |
83 return KEY_PGDWN; | |
84 case VK_RETURN: | |
85 return KEY_ENTER; | |
86 case VK_ESCAPE: | |
87 return KEY_ESC; | |
88 case VK_LEFT: | |
89 return KEY_LEFT; | |
90 case VK_UP: | |
91 return KEY_UP; | |
92 case VK_RIGHT: | |
93 return KEY_RIGHT; | |
94 case VK_DOWN: | |
95 return KEY_DOWN; | |
10230 | 96 case VK_SHIFT: |
97 continue; | |
9766 | 98 } |
99 /*check for function keys*/ | |
10230 | 100 if(0x87 >= eventbuffer[i].Event.KeyEvent.wVirtualKeyCode >= 0x70) |
9766 | 101 return (KEY_F + 1 + eventbuffer[i].Event.KeyEvent.wVirtualKeyCode - 0x70); |
102 | |
103 /*only characters should be remaining*/ | |
104 //printf("getch2: YOU PRESSED \"%c\" \n",eventbuffer[i].Event.KeyEvent.uChar.AsciiChar); | |
105 return eventbuffer[i].Event.KeyEvent.uChar.AsciiChar; | |
106 } | |
107 break; | |
108 | |
109 case MOUSE_EVENT: | |
110 case WINDOW_BUFFER_SIZE_EVENT: | |
111 case FOCUS_EVENT: | |
112 case MENU_EVENT: | |
113 default: | |
114 //printf("getch2: unsupported event type"); | |
115 break; | |
116 } | |
117 } | |
118 return -1; | |
119 } | |
120 | |
121 | |
122 void getch2_enable(){ | |
9983
14c92818ab75
alternative timer and glob emulation code for mingw32 port
faust3
parents:
9936
diff
changeset
|
123 DWORD retval; |
9936
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
124 stdin = GetStdHandle(STD_INPUT_HANDLE); |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
125 if(!GetNumberOfConsoleInputEvents(stdin,&retval)) |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
126 { |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
127 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
|
128 getch2_status = 0; |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
129 } |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
130 else getch2_status=1; |
9766 | 131 } |
132 | |
133 void getch2_disable(){ | |
134 if(!getch2_status) return; // already disabled / never enabled | |
135 getch2_status=0; | |
136 } | |
137 |