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