2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: keymap.library function MapRawKey()
8 #include <proto/arossupport.h>
9 #include <devices/inputevent.h>
10 #include <devices/keymap.h>
11 #include "keymap_intern.h"
13 #include <aros/debug.h>
15 /*****************************************************************************
18 #include <clib/keymap_protos.h>
20 AROS_LH4(WORD
, MapRawKey
,
23 AROS_LHA(struct InputEvent
*, event
, A0
),
24 AROS_LHA(STRPTR
, buffer
, A1
),
25 AROS_LHA(LONG
, length
, D1
),
26 AROS_LHA(struct KeyMap
*, keyMap
, A2
),
29 struct Library
*, KeymapBase
, 7, Keymap
)
32 Converts IECLASS_RAWKEY events to ANSI bytes.
33 The event list (event->ie_NextEvent) is not traversed!
36 event - InputEvent that should be converted.
37 ie_NextEvent is ignored!
39 buffer - buffer into which the mapped ANSI bytes will be put.
41 length - length of buffer.
43 keymap - keymap to use for mapping. If NULL, then the default
48 Actual number of chars written to the buffer. A return value of
49 -1 means buffer owerflow.
63 27-11-96 digulla automatically created from
64 keymap_lib.fd and clib/keymap_protos.h
66 *****************************************************************************/
70 struct BufInfo bufinfo
;
74 bufinfo
.Buffer
= buffer
;
75 bufinfo
.BufLength
= length
;
76 bufinfo
.CharsWritten
= 0L;
79 keyMap
= KMBase(KeymapBase
)->DefaultKeymap
;
82 /* Don't handle non-rawkey events */
83 if (event
->ie_Class
!= IECLASS_RAWKEY
)
86 code
= event
->ie_Code
;
87 qual
= event
->ie_Qualifier
;
89 /* Get info on keypress */
90 if (!GetKeyInfo(&ki
, code
, qual
, keyMap
))
91 goto done
; /* Invalid key mapping (like CTRL-ALT-A if a doesn't support CTRL-ALT */
93 /* Handle decoding of the the different keytypes (normal, KCF_STRING, KCF_DEAD and KCF_NOP) */
95 switch (ki
.Key_MapType
& (KC_NOQUAL
|KCF_STRING
|KCF_DEAD
|KCF_NOP
))
102 D(bug("mrk: KC_NOQUAL\n"));
104 D(bug("mrk: getting idx at [%d][%d]\n", ki
.Key_MapType
& KC_VANILLA
, ki
.KCFQual
));
105 idx
= keymaptype_table
[ki
.Key_MapType
& KC_VANILLA
][ki
.KCFQual
];
109 D(bug("mrk: valid qual, idx=%d, key mapping=%04x\n", idx
, ki
.Key_Mapping
));
112 D(bug("mrk: Ctrl-C mode\n"));
113 /* Special-case where bit 5 & 6 should be cleared */
115 c
= GetMapChar(ki
.Key_Mapping
, idx
);
117 /* clear bit 5 and 6 */
118 c
&= ~((1 << 5)|(1 << 6));
122 c
= GetMapChar(ki
.Key_Mapping
, idx
);
125 D(bug("mrk: Putting %c (%d 0x%x) into buffer\n", c
, c
, c
));
127 if (c
!= 0) /* If we get a 0 from the keymap, it means the char converts to "" */
129 if (!WriteToBuffer(&bufinfo
, &c
, 1))
133 } /* if (idx != -1) */
141 D(bug("mrk: KCF_STRING\n"));
143 D(bug("mrk: getting idx at [%d][%d]\n", ki
.Key_MapType
& KC_VANILLA
, ki
.KCFQual
));
144 idx
= keymapstr_table
[ki
.Key_MapType
& KC_VANILLA
][ki
.KCFQual
];
148 UBYTE
*str_descrs
= (UBYTE
*)ki
.Key_Mapping
;
151 /* Since each string descriptor uses two bytes we multiply by 2 */
154 /* Get string info from string descriptor table */
156 len
= str_descrs
[idx
];
157 offset
= str_descrs
[idx
+ 1];
159 D(bug("mrk: len=%d, offset=%d\n", len
, offset
));
161 /* Write string to buffer */
162 if (!WriteToBuffer(&bufinfo
, &(str_descrs
[offset
]), len
))
165 } /* if (idx != -1) */
174 /* Get the index to the right dead key descrptor */
175 D(bug("mrk: KCF_DEAD\n"));
177 D(bug("mrk: getting idx at [%d][%d]\n", ki
.Key_MapType
& KC_VANILLA
, ki
.KCFQual
));
178 idx
= keymapstr_table
[ki
.Key_MapType
& KC_VANILLA
][ki
.KCFQual
];
183 UBYTE
*dead_descr
= (UBYTE
*)ki
.Key_Mapping
;
187 /* Each dead descripto is 2 bytes */
190 dead_type
= dead_descr
[idx
];
191 dead_val
= dead_descr
[idx
+ 1];
196 /* Val is the key to output */
197 if (!WriteToBuffer(&bufinfo
, &dead_val
, 1))
200 else if (dead_type
== DPF_DEAD
)
202 /* Do absolutely nothing. DPF_DEAD keys
203 ** are not possible to output, and are not
204 ** interesting by themselves.
205 ** However, if a DPF_MOD key follows..
209 else if (dead_type
== DPF_MOD
)
211 /* Now, lets have a look at the last two previous
214 ** dk_idx defaults to 0, which is the index to use if it turns out that
215 ** the deadable key had no valid deadkeys before it
217 WORD dk_idx
= 0; /* Defaults to 0, which is the index to be used into the transition table */
220 /* Get deadkey index for Prev1 */
221 dki_1
= GetDeadKeyIndex(event
->ie_Prev1DownCode
, event
->ie_Prev1DownQual
, keyMap
);
222 if (dki_1
!= -1) /* Was it a dead key ? */
226 /* Is this a double deadkey (higher nibble set ?) */
227 if (dki_1
>> DP_2DFACSHIFT
)
231 dk_idx
= (dki_1
& DP_2DINDEXMASK
) * (dki_1
>> DP_2DFACSHIFT
);
233 dki_2
= GetDeadKeyIndex(event
->ie_Prev2DownCode
, event
->ie_Prev2DownQual
, keyMap
);
234 if (dki_2
!= -1) /* Was it a dead key ? */
236 /* Compute deadkey index - explained in RKM:L p. 826 */
237 dk_idx
+= (dki_2
& DP_2DINDEXMASK
);
242 dead_val
= dead_descr
[dead_val
+ dk_idx
];
244 if (!WriteToBuffer(&bufinfo
, &dead_val
, 1))
250 D(bug("Keymap contains illegal deadkey type for code %04x, event->ie_Code\n"));
254 } /* if (idx != -1) */
263 D(bug("Error in keymap, more than one decode action specified for code %04x\n", event
->ie_Code
));
266 } /* switch (ki.Key_MapType & (KC_NOQUAL|KCF_STRING|KCF_DEAD|KCF_NOP)) */
269 ReturnInt ("MapRawKey", WORD
, bufinfo
.CharsWritten
);
272 ReturnInt ("MapRawKey", WORD
, -1);