forwarding a radium compilation fix.
[AROS-Contrib.git] / fish / input / input.c
blobc97d4987812aee4dd5ad237b44ce04107f696233
1 /********************************************
2 * INPUT.C 08/04/90
3 * © Copyright 1990 Timm Martin
4 * This source code is freely distributable
5 * and may be used without compensation in
6 * any commercial or non-commercial product
7 * as long as this notice is included and
8 * remains intact. This code may be used
9 * in an executable program without
10 * acknowledgement of the author.
11 *********************************************/
13 #include <aros/oldprograms.h>
14 #include <proto/console.h>
16 #include <devices/inputevent.h>
17 #include <exec/types.h>
18 #include <intuition/intuition.h>
19 #include "input.h"
21 extern struct Device *ConsoleDevice;
23 /*************
24 * INPUT KEY
25 **************/
28 Given a pointer to the IntuiMessage structure received for the current window
29 by Intuition, this function will return the key that was pressed, or zero if
30 no valid key was pressed.
33 #define QUAL ievent.ie_Qualifier
34 #define SIZE 20L
36 USHORT input_key( struct IntuiMessage *imessage )
38 UBYTE buffer[SIZE]; /* buffer into which raw key conversion is read */
39 short codes = 0; /* number of ANSI codes returned */
40 static struct InputEvent ievent = { NULL, IECLASS_RAWKEY, 0, 0, 0 };
41 USHORT key = 0; /* key value returned by this function (see below) */
42 USHORT qual = 0; /* key qualifiers (shift, alt, ctl, etc.) */
44 /* copy rawkey codes and qualifiers into InputEvent structure for conversion */
45 ievent.ie_Code = imessage->Code;
46 QUAL = imessage->Qualifier;
50 LG = left Amiga key RG = right Amiga key
51 LA = left ALT key RA = right ALT key
52 LS = left SHIFT key RS = right SHIFT key
53 CT = ConTRoL key
54 CO = command key
56 Format of the imessage->Qualifier variable (necessary bits only):
58 RG LG RA LA CT RS LS <-- keys
59 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 <-- bits
61 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 <-- mask
62 | | | <-- bytes
63 0 0 F 8 <-- hex
64 <------- 8 bit positions -------< <-- shift left
65 RG LG RA LA CT <-- new pos
66 and
67 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 <-- mask
68 | | | <-- bytes
69 0 0 0 3 <-- hex
70 <--------- 9 bit positions ---------< <-- shift left
71 RS LS <-- new pos
73 Format of the "key" variable returned by sfInputKey() function:
75 RG LG RA LA CT RS LS CO (-------- key value ---------)
76 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 <-- bits
78 where key value equals:
79 if CO (command) bit set (== 1):
80 command key value as defined in input.h
81 if CO (command) bit cleared (== 0):
82 ASCII value of key pressed
86 /* determine key qualifier as shown above */
87 qual = ((QUAL & 0xf8) << 8) | ((QUAL & 0x03) << 9);
89 /* if control key, ignore this fact so that RawKeyConvert() will process
90 * (remember that the console device processes some control key sequences
91 * as other keys, for example, ^M equals RETURN)
93 if (QUAL & IEQUALIFIER_CONTROL)
94 QUAL &= ~IEQUALIFIER_CONTROL;
96 /* used for converting dead keys */
97 ievent.ie_position.ie_addr = *((APTR *)imessage->IAddress);
98 /* convert rawkey */
99 codes = RawKeyConvert( &ievent, (char *)buffer, SIZE, NULL );
101 /* if any codes returned (i.e., down transition and not a dead key) */
102 if (codes)
104 switch (buffer[0])
106 /* single code keys */
107 case 0x1b: key = COMMAND_ESCAPE; break;
108 case 0x08: key = COMMAND_BACKSPACE; break;
109 case 0x7f: key = COMMAND_DELETE; break;
110 case 0x09: key = COMMAND_TAB; break;
111 case 0x0d: key = COMMAND_RETURN; break;
112 case 0x9b:
113 if (codes > 1)
115 /* "escape" code keys */
116 switch (buffer[1])
118 case 0x5a: key = COMMAND_TAB; break; /* shift-TAB */
119 case 0x3f: key = COMMAND_HELP; break;
120 case 0x54:
121 case 0x41: key = COMMAND_UP_ARROW; break;
122 case 0x53:
123 case 0x42: key = COMMAND_DOWN_ARROW; break;
124 case 0x43: key = COMMAND_RIGHT_ARROW; break;
125 case 0x44: key = COMMAND_LEFT_ARROW; break;
126 case 0x20:
127 switch (buffer[2])
129 /* shifted-arrow keys */
130 case 0x40: key = COMMAND_RIGHT_ARROW; break;
131 case 0x41: key = COMMAND_LEFT_ARROW; break;
133 break;
134 default:
135 /* function keys F1-F10 */
136 if (buffer[2] == 0x7e)
137 key = COMMAND_F1 + (int)buffer[1]-0x30;
138 else if (buffer[3] == 0x7e)
139 key = COMMAND_F1 + (int)buffer[2]-0x30;
140 break;
143 else
144 key = COMMAND_ESCAPE;
145 break;
147 /* if key!=0, a command key was pressed */
148 if (key)
149 key += QUAL_COMMAND;
150 /* else no command key, must've been ASCII character */
151 else
152 key = buffer[0];
154 /* attach qualifiers to key */
155 if (key)
156 key += qual;
158 return (key);