#ifndef _IOHIKEYBOARD_H
#define _IOHIKEYBOARD_H
#include <IOKit/hidsystem/IOHIDevice.h>
#include <IOKit/hidsystem/IOHIKeyboardMapper.h>
typedef void (*KeyboardEventAction)( OSObject * target,
unsigned eventType,
unsigned flags,
unsigned key,
unsigned charCode,
unsigned charSet,
unsigned origCharCode,
unsigned origCharSet,
unsigned keyboardType,
bool repeat,
AbsoluteTime ts);
typedef void (*KeyboardSpecialEventAction)(OSObject * target,
unsigned eventType,
unsigned flags,
unsigned key,
unsigned flavor,
UInt64 guid,
bool repeat,
AbsoluteTime ts);
typedef void (*UpdateEventFlagsAction)( OSObject * target,
unsigned flags);
typedef void (*KeyboardEventCallback)(
OSObject * target,
unsigned eventType,
unsigned flags,
unsigned key,
unsigned charCode,
unsigned charSet,
unsigned origCharCode,
unsigned origCharSet,
unsigned keyboardType,
bool repeat,
AbsoluteTime ts,
OSObject * sender,
void * refcon);
typedef void (*KeyboardSpecialEventCallback)(
OSObject * target,
unsigned eventType,
unsigned flags,
unsigned key,
unsigned flavor,
UInt64 guid,
bool repeat,
AbsoluteTime ts,
OSObject * sender,
void * refcon);
typedef void (*UpdateEventFlagsCallback)(
OSObject * target,
unsigned flags,
OSObject * sender,
void * refcon);
#define EV_DEFAULTINITIALREPEAT 500000000ULL // 1/2 sec in nanoseconds
#define EV_DEFAULTKEYREPEAT 83333333ULL // 1/12 sec in nanoseconds
#define EV_MINKEYREPEAT 16700000ULL // 1/60 sec
class IOHIKeyboard : public IOHIDevice
{
OSDeclareDefaultStructors(IOHIKeyboard);
friend class IOHIDKeyboardDevice;
friend class IOHIDKeyboard;
friend class IOHIDConsumer;
protected:
IOLock * _deviceLock; IOHIKeyboardMapper * _keyMap;
UInt32 _interfaceType;
UInt32 _deviceType;
UInt32 * _keyState; IOByteCount _keyStateSize; unsigned _eventFlags; bool _alphaLock; bool _numLock; bool _charKeyActive;
bool _isRepeat; unsigned _codeToRepeat; bool _calloutPending; AbsoluteTime _lastEventTime; AbsoluteTime _downRepeatTime; AbsoluteTime _keyRepeat; AbsoluteTime _initialKeyRepeat; UInt64 _guid;
OSObject * _keyboardEventTarget;
KeyboardEventAction _keyboardEventAction;
OSObject * _keyboardSpecialEventTarget;
KeyboardSpecialEventAction _keyboardSpecialEventAction;
OSObject * _updateEventFlagsTarget;
UpdateEventFlagsAction _updateEventFlagsAction;
UInt16 _lastUsagePage;
UInt16 _lastUsage;
protected:
virtual void dispatchKeyboardEvent(unsigned int keyCode,
bool goingDown,
AbsoluteTime time);
void setLastPageAndUsage(UInt16 usagePage, UInt16 usage);
void getLastPageAndUsage(UInt16 &usagePage, UInt16 &usage);
void clearLastPageAndUsage();
public:
virtual bool init(OSDictionary * properties = 0);
virtual bool start(IOService * provider);
virtual void stop(IOService * provider);
virtual void free();
virtual bool open(IOService * client,
IOOptionBits options,
KeyboardEventAction keAction,
KeyboardSpecialEventAction kseAction,
UpdateEventFlagsAction uefAction);
bool open( IOService * client,
IOOptionBits options,
void *,
KeyboardEventCallback keCallback,
KeyboardSpecialEventCallback kseCallback,
UpdateEventFlagsCallback uefCallback);
virtual void close(IOService * client, IOOptionBits );
virtual IOReturn message( UInt32 type, IOService * provider,
void * argument = 0 );
virtual IOHIDKind hidKind();
virtual bool updateProperties( void );
virtual IOReturn setParamProperties(OSDictionary * dict);
virtual IOReturn setProperties( OSObject * properties );
inline bool isRepeat() {return _isRepeat;}
protected: virtual const unsigned char * defaultKeymapOfLength(UInt32 * length);
virtual void setAlphaLockFeedback(bool val);
virtual void setNumLockFeedback(bool val);
virtual UInt32 maxKeyCodes();
private:
virtual bool resetKeyboard();
virtual void scheduleAutoRepeat();
static void _autoRepeat(void * arg, void *);
virtual void autoRepeat();
virtual void setRepeat(unsigned eventType, unsigned keyCode);
void setRepeatMode(bool repeat);
static void _createKeyboardNub(thread_call_param_t param0, thread_call_param_t param1);
public:
virtual void keyboardEvent(unsigned eventType,
unsigned flags,
unsigned keyCode,
unsigned charCode,
unsigned charSet,
unsigned origCharCode,
unsigned origCharSet);
virtual void keyboardSpecialEvent(unsigned eventType,
unsigned flags,
unsigned keyCode,
unsigned flavor);
virtual void updateEventFlags(unsigned flags);
virtual unsigned eventFlags(); virtual unsigned deviceFlags(); virtual void setDeviceFlags(unsigned flags); virtual bool alphaLock(); virtual void setAlphaLock(bool val); virtual bool numLock();
virtual void setNumLock(bool val);
virtual bool charKeyActive(); virtual void setCharKeyActive(bool val); virtual bool doesKeyLock(unsigned key); virtual unsigned getLEDStatus();
virtual IOReturn newUserClient( task_t owningTask,
void * security_id,
UInt32 type,
OSDictionary * properties,
IOUserClient ** handler );
IOReturn newUserClientGated(task_t owningTask,
void * security_id,
OSDictionary * properties,
IOUserClient ** handler );
virtual bool attachToChild( IORegistryEntry * child,
const IORegistryPlane * plane );
virtual void detachFromChild( IORegistryEntry * child,
const IORegistryPlane * plane );
private:
static void _keyboardEvent( IOHIKeyboard * self,
unsigned eventType,
unsigned flags,
unsigned key,
unsigned charCode,
unsigned charSet,
unsigned origCharCode,
unsigned origCharSet,
unsigned keyboardType,
bool repeat,
AbsoluteTime ts);
static void _keyboardSpecialEvent(
IOHIKeyboard * self,
unsigned eventType,
unsigned flags,
unsigned key,
unsigned flavor,
UInt64 guid,
bool repeat,
AbsoluteTime ts);
static void _updateEventFlags( IOHIKeyboard * self,
unsigned flags);
bool postSecureKey(UInt8 key, bool down);
};
#endif