annotate osdep/getch2-win.c @ 20707:a8d7e977ca8d

Initial partial translation of man page (synced with last SVN). TODO: Translate sections: "VIDEO OUTPUT DRIVERS" "DECODING/FILTERING OPTIONS" "AUDIO FILTERS" "VIDEO FILTERS" "GENERAL ENCODING OPTIONS" "CODEC SPECIFIC ENCODING OPTIONS" Resolve all FIXME issues.
author voroshil
date Sun, 05 Nov 2006 19:04:41 +0000
parents 24003616a623
children 6f183c95aafc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
1 /* windows TermIO for MPlayer (C) 2003 Sascha Sommer */
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
2
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
3 // See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/VirtualKeyCodes.asp
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
4 // for additional virtual keycodes
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
5
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
6
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
7 #include <windows.h>
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
8 #include "keycodes.h"
16985
08cac43f1e38 Unify include paths, -I.. is in CFLAGS.
diego
parents: 13015
diff changeset
9 #include "input/input.h"
10928
f2313bd91594 add a read function for slave mode on mingw
faust3
parents: 10230
diff changeset
10
f2313bd91594 add a read function for slave mode on mingw
faust3
parents: 10230
diff changeset
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
f2313bd91594 add a read function for slave mode on mingw
faust3
parents: 10230
diff changeset
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
f2313bd91594 add a read function for slave mode on mingw
faust3
parents: 10230
diff changeset
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
f2313bd91594 add a read function for slave mode on mingw
faust3
parents: 10230
diff changeset
20 return MP_INPUT_NOTHING;
f2313bd91594 add a read function for slave mode on mingw
faust3
parents: 10230
diff changeset
21 }
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
22
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
23 int screen_width=80;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
24 int screen_height=24;
17258
3d02f6e2a432 change erase to end of line, fall back to old behavior if no termcap found
ods15
parents: 17251
diff changeset
25 char * erase_to_end_of_line = NULL;
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
26
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
27 void get_screen_size(){
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
28 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
29
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
30 static HANDLE stdin;
9936
6d9531a5d95b disable getch2 on windows when we can't read stdin (msys)
faust3
parents: 9766
diff changeset
31 static int getch2_status=0;
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
32
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
33 int getch2(int time){
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
34 INPUT_RECORD eventbuffer[128];
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
35 DWORD retval;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
36 int i=0;
9936
6d9531a5d95b disable getch2 on windows when we can't read stdin (msys)
faust3
parents: 9766
diff changeset
37 if(!getch2_status)return -1;
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
38 /*check if there are input events*/
18070
c1e25c011c54 getch2 should wait for input. Fixes 100% CPU usage during cache fill.
reimar
parents: 17258
diff changeset
39 WaitForSingleObject(stdin, time);
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
40 if(!GetNumberOfConsoleInputEvents(stdin,&retval))
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
41 {
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
42 printf("getch2: can't get number of input events: %i\n",GetLastError());
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
43 return -1;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
44 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
45 if(retval<=0)return -1;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
46
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
47 /*read all events*/
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
48 if(!ReadConsoleInput(stdin,eventbuffer,128,&retval))
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
49 {
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
50 printf("getch: can't read input events\n");
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
51 return -1;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
52 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
53
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
54 /*filter out keyevents*/
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
55 for (i = 0; i < retval; i++)
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
56 {
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
57 switch(eventbuffer[i].EventType)
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
58 {
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
59 case KEY_EVENT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
60 /*only a pressed key is interresting for us*/
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
61 if(eventbuffer[i].Event.KeyEvent.bKeyDown == TRUE)
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
62 {
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
63 /*check for special keys*/
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
64 switch(eventbuffer[i].Event.KeyEvent.wVirtualKeyCode)
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
65 {
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
66 case VK_HOME:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
67 return KEY_HOME;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
68 case VK_END:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
69 return KEY_END;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
70 case VK_DELETE:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
71 return KEY_DEL;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
72 case VK_INSERT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
73 return KEY_INS;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
74 case VK_BACK:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
75 return KEY_BS;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
76 case VK_PRIOR:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
77 return KEY_PGUP;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
78 case VK_NEXT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
79 return KEY_PGDWN;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
80 case VK_RETURN:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
81 return KEY_ENTER;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
82 case VK_ESCAPE:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
83 return KEY_ESC;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
84 case VK_LEFT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
85 return KEY_LEFT;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
86 case VK_UP:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
87 return KEY_UP;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
88 case VK_RIGHT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
89 return KEY_RIGHT;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
90 case VK_DOWN:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
91 return KEY_DOWN;
10230
3d33d5a19c21 fix volume increasing
faust3
parents: 9983
diff changeset
92 case VK_SHIFT:
3d33d5a19c21 fix volume increasing
faust3
parents: 9983
diff changeset
93 continue;
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
94 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
95 /*check for function keys*/
18107
24003616a623 10l, fix broken if (X >= Y >= Z) comparison, probably stopped F-keys from working
reimar
parents: 18070
diff changeset
96 if(0x87 >= eventbuffer[i].Event.KeyEvent.wVirtualKeyCode && eventbuffer[i].Event.KeyEvent.wVirtualKeyCode >= 0x70)
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
97 return (KEY_F + 1 + eventbuffer[i].Event.KeyEvent.wVirtualKeyCode - 0x70);
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
98
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
99 /*only characters should be remaining*/
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
100 //printf("getch2: YOU PRESSED \"%c\" \n",eventbuffer[i].Event.KeyEvent.uChar.AsciiChar);
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
101 return eventbuffer[i].Event.KeyEvent.uChar.AsciiChar;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
102 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
103 break;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
104
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
105 case MOUSE_EVENT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
106 case WINDOW_BUFFER_SIZE_EVENT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
107 case FOCUS_EVENT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
108 case MENU_EVENT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
109 default:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
110 //printf("getch2: unsupported event type");
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
111 break;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
112 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
113 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
114 return -1;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
115 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
116
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
117
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
118 void getch2_enable(){
9983
14c92818ab75 alternative timer and glob emulation code for mingw32 port
faust3
parents: 9936
diff changeset
119 DWORD retval;
9936
6d9531a5d95b disable getch2 on windows when we can't read stdin (msys)
faust3
parents: 9766
diff changeset
120 stdin = GetStdHandle(STD_INPUT_HANDLE);
6d9531a5d95b disable getch2 on windows when we can't read stdin (msys)
faust3
parents: 9766
diff changeset
121 if(!GetNumberOfConsoleInputEvents(stdin,&retval))
6d9531a5d95b disable getch2 on windows when we can't read stdin (msys)
faust3
parents: 9766
diff changeset
122 {
6d9531a5d95b disable getch2 on windows when we can't read stdin (msys)
faust3
parents: 9766
diff changeset
123 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
124 getch2_status = 0;
6d9531a5d95b disable getch2 on windows when we can't read stdin (msys)
faust3
parents: 9766
diff changeset
125 }
6d9531a5d95b disable getch2 on windows when we can't read stdin (msys)
faust3
parents: 9766
diff changeset
126 else getch2_status=1;
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
127 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
128
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
129 void getch2_disable(){
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
130 if(!getch2_status) return; // already disabled / never enabled
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
131 getch2_status=0;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
132 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
133