Mercurial > mplayer.hg
annotate osdep/getch2-win.c @ 20473:6ebbcbeae8c1
Cleanup/simplify nsv check_file function.
author | reimar |
---|---|
date | Sat, 28 Oct 2006 11:01:18 +0000 |
parents | 24003616a623 |
children | 6f183c95aafc |
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*/ |
18070
c1e25c011c54
getch2 should wait for input. Fixes 100% CPU usage during cache fill.
reimar
parents:
17258
diff
changeset
|
39 WaitForSingleObject(stdin, time); |
9766 | 40 if(!GetNumberOfConsoleInputEvents(stdin,&retval)) |
41 { | |
42 printf("getch2: can't get number of input events: %i\n",GetLastError()); | |
43 return -1; | |
44 } | |
45 if(retval<=0)return -1; | |
46 | |
47 /*read all events*/ | |
48 if(!ReadConsoleInput(stdin,eventbuffer,128,&retval)) | |
49 { | |
50 printf("getch: can't read input events\n"); | |
51 return -1; | |
52 } | |
53 | |
54 /*filter out keyevents*/ | |
55 for (i = 0; i < retval; i++) | |
56 { | |
57 switch(eventbuffer[i].EventType) | |
58 { | |
59 case KEY_EVENT: | |
60 /*only a pressed key is interresting for us*/ | |
61 if(eventbuffer[i].Event.KeyEvent.bKeyDown == TRUE) | |
62 { | |
63 /*check for special keys*/ | |
64 switch(eventbuffer[i].Event.KeyEvent.wVirtualKeyCode) | |
65 { | |
66 case VK_HOME: | |
67 return KEY_HOME; | |
68 case VK_END: | |
69 return KEY_END; | |
70 case VK_DELETE: | |
71 return KEY_DEL; | |
72 case VK_INSERT: | |
73 return KEY_INS; | |
74 case VK_BACK: | |
75 return KEY_BS; | |
76 case VK_PRIOR: | |
77 return KEY_PGUP; | |
78 case VK_NEXT: | |
79 return KEY_PGDWN; | |
80 case VK_RETURN: | |
81 return KEY_ENTER; | |
82 case VK_ESCAPE: | |
83 return KEY_ESC; | |
84 case VK_LEFT: | |
85 return KEY_LEFT; | |
86 case VK_UP: | |
87 return KEY_UP; | |
88 case VK_RIGHT: | |
89 return KEY_RIGHT; | |
90 case VK_DOWN: | |
91 return KEY_DOWN; | |
10230 | 92 case VK_SHIFT: |
93 continue; | |
9766 | 94 } |
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 | 97 return (KEY_F + 1 + eventbuffer[i].Event.KeyEvent.wVirtualKeyCode - 0x70); |
98 | |
99 /*only characters should be remaining*/ | |
100 //printf("getch2: YOU PRESSED \"%c\" \n",eventbuffer[i].Event.KeyEvent.uChar.AsciiChar); | |
101 return eventbuffer[i].Event.KeyEvent.uChar.AsciiChar; | |
102 } | |
103 break; | |
104 | |
105 case MOUSE_EVENT: | |
106 case WINDOW_BUFFER_SIZE_EVENT: | |
107 case FOCUS_EVENT: | |
108 case MENU_EVENT: | |
109 default: | |
110 //printf("getch2: unsupported event type"); | |
111 break; | |
112 } | |
113 } | |
114 return -1; | |
115 } | |
116 | |
117 | |
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 | 127 } |
128 | |
129 void getch2_disable(){ | |
130 if(!getch2_status) return; // already disabled / never enabled | |
131 getch2_status=0; | |
132 } | |
133 |