annotate osdep/getch2-win.c @ 10464:5688e1b24c98

sync
author diego
date Thu, 24 Jul 2003 10:54:09 +0000
parents 3d33d5a19c21
children f2313bd91594
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"
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
9
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
10 int screen_width=80;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
11 int screen_height=24;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
12
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
13 void get_screen_size(){
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
14 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
15
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
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
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
18
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
19 int getch2(int time){
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
20 INPUT_RECORD eventbuffer[128];
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
21 DWORD retval;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
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
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
24 /*check if there are input events*/
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
25 if(!GetNumberOfConsoleInputEvents(stdin,&retval))
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
26 {
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
27 printf("getch2: can't get number of input events: %i\n",GetLastError());
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
28 return -1;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
29 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
30 if(retval<=0)return -1;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
31
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
32 /*read all events*/
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
33 if(!ReadConsoleInput(stdin,eventbuffer,128,&retval))
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
34 {
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
35 printf("getch: can't read input events\n");
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
36 return -1;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
37 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
38
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
39 /*filter out keyevents*/
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
40 for (i = 0; i < retval; i++)
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
41 {
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
42 switch(eventbuffer[i].EventType)
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
43 {
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
44 case KEY_EVENT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
45 /*only a pressed key is interresting for us*/
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
46 if(eventbuffer[i].Event.KeyEvent.bKeyDown == TRUE)
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
47 {
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
48 /*check for special keys*/
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
49 switch(eventbuffer[i].Event.KeyEvent.wVirtualKeyCode)
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
50 {
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
51 case VK_HOME:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
52 return KEY_HOME;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
53 case VK_END:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
54 return KEY_END;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
55 case VK_DELETE:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
56 return KEY_DEL;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
57 case VK_INSERT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
58 return KEY_INS;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
59 case VK_BACK:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
60 return KEY_BS;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
61 case VK_PRIOR:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
62 return KEY_PGUP;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
63 case VK_NEXT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
64 return KEY_PGDWN;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
65 case VK_RETURN:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
66 return KEY_ENTER;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
67 case VK_ESCAPE:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
68 return KEY_ESC;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
69 case VK_LEFT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
70 return KEY_LEFT;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
71 case VK_UP:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
72 return KEY_UP;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
73 case VK_RIGHT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
74 return KEY_RIGHT;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
75 case VK_DOWN:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
76 return KEY_DOWN;
10230
3d33d5a19c21 fix volume increasing
faust3
parents: 9983
diff changeset
77 case VK_SHIFT:
3d33d5a19c21 fix volume increasing
faust3
parents: 9983
diff changeset
78 continue;
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
79 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
80 /*check for function keys*/
10230
3d33d5a19c21 fix volume increasing
faust3
parents: 9983
diff changeset
81 if(0x87 >= eventbuffer[i].Event.KeyEvent.wVirtualKeyCode >= 0x70)
9766
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
82 return (KEY_F + 1 + eventbuffer[i].Event.KeyEvent.wVirtualKeyCode - 0x70);
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
83
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
84 /*only characters should be remaining*/
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
85 //printf("getch2: YOU PRESSED \"%c\" \n",eventbuffer[i].Event.KeyEvent.uChar.AsciiChar);
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
86 return eventbuffer[i].Event.KeyEvent.uChar.AsciiChar;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
87 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
88 break;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
89
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
90 case MOUSE_EVENT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
91 case WINDOW_BUFFER_SIZE_EVENT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
92 case FOCUS_EVENT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
93 case MENU_EVENT:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
94 default:
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
95 //printf("getch2: unsupported event type");
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
96 break;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
97 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
98 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
99 return -1;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
100 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
101
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
102
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
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
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 void getch2_disable(){
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
115 if(!getch2_status) return; // already disabled / never enabled
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
116 getch2_status=0;
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
117 }
afb1150cd5de windows getch2 for MINGW32 port
faust3
parents:
diff changeset
118