2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 #ifndef _IOHIKEYBOARDMAPPER_H
23 #define _IOHIKEYBOARDMAPPER_H
25 #include <IOKit/hidsystem/ev_keymap.h>
30 * Key ip/down state is tracked in a bit list. Bits are set
31 * for key-down, and cleared for key-up. The bit vector and macros
32 * for it's manipulation are defined here.
35 typedef UInt32
* kbdBitVector
;
37 #define EVK_BITS_PER_UNIT 32
38 #define EVK_BITS_MASK 31
39 #define EVK_BITS_SHIFT 5 // 1<<5 == 32, for cheap divide
41 #define EVK_KEYDOWN(n, bits) \
42 (bits)[((n)>>EVK_BITS_SHIFT)] |= (1 << ((n) & EVK_BITS_MASK))
44 #define EVK_KEYUP(n, bits) \
45 (bits)[((n)>>EVK_BITS_SHIFT)] &= ~(1 << ((n) & EVK_BITS_MASK))
47 #define EVK_IS_KEYDOWN(n, bits) \
48 (((bits)[((n)>>EVK_BITS_SHIFT)] & (1 << ((n) & EVK_BITS_MASK))) != 0)
50 class IOHIKeyboardMapper
: public OSObject
52 OSDeclareDefaultStructors(IOHIKeyboardMapper
);
55 IOHIKeyboard
* _delegate
; // KeyMap delegate
56 bool _mappingShouldBeFreed
; // true if map can be IOFree'd
57 NXParsedKeyMapping _parsedMapping
; // current system-wide keymap
60 static IOHIKeyboardMapper
* keyboardMapper(
61 IOHIKeyboard
* delegate
,
62 const UInt8
* mapping
,
64 bool mappingShouldBeFreed
);
66 virtual bool init(IOHIKeyboard
* delegate
,
67 const UInt8
* mapping
,
69 bool mappingShouldBeFreed
);
72 virtual const UInt8
* mapping();
73 virtual UInt32
mappingLength();
74 virtual bool serialize(OSSerialize
*s
) const;
76 virtual void translateKeyCode(UInt8 key
, bool keyDown
, kbdBitVector keyBits
);
77 virtual UInt8
getParsedSpecialKey(UInt8 logical
); //retrieve a key from _parsedMapping
81 virtual bool parseKeyMapping(const UInt8
* mapping
,
83 NXParsedKeyMapping
* parsedMapping
) const;
85 virtual void calcModBit(int bit
, kbdBitVector keyBits
);
86 virtual void doModCalc(int key
, kbdBitVector keyBits
);
87 virtual void doCharGen(int keyCode
, bool down
);
90 #endif _IOHIKEYBOARDMAPPER_H
94 * The "delegate" object had to respond to the following protocol;
95 * this protocol has since been merged into the IOHIKeyboard class.
97 * @protocol KeyMapDelegate
99 * - keyboardEvent :(unsigned)eventType
100 * flags :(unsigned)flags
101 * keyCode :(unsigned)keyCode
102 * charCode:(unsigned)charCode
103 * charSet :(unsigned)charSet
104 * originalCharCode:(unsigned)origCharCode
105 * originalCharSet:(unsigned)origCharSet;
107 * - keyboardSpecialEvent:(unsigned)eventType
108 * flags :(unsigned)flags
109 * keyCode :(unsigned)keyCode
110 * specialty:(unsigned)flavor;
112 * - updateEventFlags:(unsigned)flags; // Does not generate events
114 * - (unsigned)eventFlags; // Global event flags
115 * - (unsigned)deviceFlags; // per-device event flags
116 * - setDeviceFlags:(unsigned)flags; // Set device event flags
117 * - (bool)alphaLock; // current alpha-lock state
118 * - setAlphaLock:(bool)val; // Set current alpha-lock state
119 * - (bool)charKeyActive; // Is a character gen. key down?
120 * - setCharKeyActive:(bool)val; // Note that a char gen key is down.