Mercurial > mplayer.hg
annotate osdep/getch2-win.c @ 10343:b277842a74a2
merged with mpg123 0.59s-pre
author | arpi |
---|---|
date | Sat, 28 Jun 2003 22:52:36 +0000 |
parents | 3d33d5a19c21 |
children | f2313bd91594 |
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" | |
9 | |
10 int screen_width=80; | |
11 int screen_height=24; | |
12 | |
13 void get_screen_size(){ | |
14 } | |
15 | |
16 static HANDLE stdin; | |
9936
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
17 static int getch2_status=0; |
9766 | 18 |
19 int getch2(int time){ | |
20 INPUT_RECORD eventbuffer[128]; | |
21 DWORD retval; | |
22 int i=0; | |
9936
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
23 if(!getch2_status)return -1; |
9766 | 24 /*check if there are input events*/ |
25 if(!GetNumberOfConsoleInputEvents(stdin,&retval)) | |
26 { | |
27 printf("getch2: can't get number of input events: %i\n",GetLastError()); | |
28 return -1; | |
29 } | |
30 if(retval<=0)return -1; | |
31 | |
32 /*read all events*/ | |
33 if(!ReadConsoleInput(stdin,eventbuffer,128,&retval)) | |
34 { | |
35 printf("getch: can't read input events\n"); | |
36 return -1; | |
37 } | |
38 | |
39 /*filter out keyevents*/ | |
40 for (i = 0; i < retval; i++) | |
41 { | |
42 switch(eventbuffer[i].EventType) | |
43 { | |
44 case KEY_EVENT: | |
45 /*only a pressed key is interresting for us*/ | |
46 if(eventbuffer[i].Event.KeyEvent.bKeyDown == TRUE) | |
47 { | |
48 /*check for special keys*/ | |
49 switch(eventbuffer[i].Event.KeyEvent.wVirtualKeyCode) | |
50 { | |
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; | |
10230 | 77 case VK_SHIFT: |
78 continue; | |
9766 | 79 } |
80 /*check for function keys*/ | |
10230 | 81 if(0x87 >= eventbuffer[i].Event.KeyEvent.wVirtualKeyCode >= 0x70) |
9766 | 82 return (KEY_F + 1 + eventbuffer[i].Event.KeyEvent.wVirtualKeyCode - 0x70); |
83 | |
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; | |
87 } | |
88 break; | |
89 | |
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; | |
97 } | |
98 } | |
99 return -1; | |
100 } | |
101 | |
102 | |
103 void getch2_enable(){ | |
9983
14c92818ab75
alternative timer and glob emulation code for mingw32 port
faust3
parents:
9936
diff
changeset
|
104 DWORD retval; |
9936
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
105 stdin = GetStdHandle(STD_INPUT_HANDLE); |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
106 if(!GetNumberOfConsoleInputEvents(stdin,&retval)) |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
107 { |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
108 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
|
109 getch2_status = 0; |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
110 } |
6d9531a5d95b
disable getch2 on windows when we can't read stdin (msys)
faust3
parents:
9766
diff
changeset
|
111 else getch2_status=1; |
9766 | 112 } |
113 | |
114 void getch2_disable(){ | |
115 if(!getch2_status) return; // already disabled / never enabled | |
116 getch2_status=0; | |
117 } | |
118 |