forked from EMlyDinEsHMG/AsusNBFnKeys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FnkeysHIKeyboard.cpp
188 lines (143 loc) · 5.66 KB
/
FnkeysHIKeyboard.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
* Copyright (c) 2012 - 2013 EMlyDinEsH(OSXLatitude). All rights reserved.
*
*
* FnKeysHIDKeyboard.cpp
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <IOKit/acpi/IOACPIPlatformDevice.h>
#include <IOKit/hidsystem/ev_keymap.h>
#include "FnKeysHIKeyboard.h"
#define super IOHIKeyboard
OSDefineMetaClassAndStructors(FnKeysHIKeyboard, IOHIKeyboard)
#pragma mark -
#pragma mark IOService override
#pragma mark -
bool FnKeysHIKeyboard::init(OSDictionary *dictionary)
{
return super::init(dictionary);
}
bool FnKeysHIKeyboard::start(IOService *provider)
{
if(!provider || !super::start( provider ))
{
IOLog("%s: Failed to load..\n", this->getName());
return false;
}
Device = (FnKeysHIKeyboardDevice *) provider;
clock_get_system_microtime(&lastEventSecs,&lastEventMicrosecs);
setProperty("Product", "Fn Keys Keyboard for Asus");
return true;
}
void FnKeysHIKeyboard::stop(IOService *provider)
{
super::stop(provider);
}
void FnKeysHIKeyboard::free(void)
{
super::free();
}
/*
* Receive hotkey event (only down) and send keyboard down and up event
* Limits the rate of event send to HID stack, otherwise the system slow down and the sound/sun bezel lags.
*/
IOReturn FnKeysHIKeyboard::message( UInt32 type, IOService * provider, void * argument)
{
if (type == kIOACPIMessageDeviceNotification)
{
clock_sec_t secs, deltaSecs;
clock_usec_t microsecs, deltaMicrosecs;
clock_get_system_microtime(&secs,µsecs);
deltaSecs = secs - lastEventSecs;
/*if (deltaSecs < 2)
{
deltaMicrosecs = microsecs + (1000000 * deltaSecs) - lastEventMicrosecs;
if (deltaMicrosecs < 125000) // rate limiter to 125 ms
return kIOReturnSuccess;
}
lastEventSecs = secs;
lastEventMicrosecs = microsecs;*/
{
UInt32 code = *((UInt32 *) argument);
AbsoluteTime now;
clock_get_uptime((uint64_t *)(&now));
dispatchKeyboardEvent( code,
/*direction*/ true,
/*timeStamp*/ now );
clock_get_uptime((uint64_t *)(&now));
dispatchKeyboardEvent( code,
/*direction*/ false,
/*timeStamp*/ now );
//IOLog("Dispatched Key: %d %x\n",code,code);
}
}
return kIOReturnSuccess;
}
#pragma mark -
#pragma mark IOHIKeyboard override
#pragma mark -
//====================================================================================================
// defaultKeymapOfLength - IOHIKeyboard override
// This allows us to associate the scancodes we choose with the special
// keys we are interested in posting later. This gives us auto-repeats for free. Kewl.
//====================================================================================================
const unsigned char * FnKeysHIKeyboard::defaultKeymapOfLength( UInt32 * length )
{
static const unsigned char ConsumerKeyMap[] =
{
// The first 16 bits are always read first, to determine if the rest of
// the keymap is in shorts (16 bits) or bytes (8 bits). If the first 16 bits
// equals 0, data is in bytes; if first 16 bits equal 1, data is in shorts.
0x00,0x00, // data is in bytes
// The next value is the number of modifier keys. We have none in our driver.
0x00,
// The next value is number of key definitions. We have none in our driver.
0x00,
// The next value is number of of sequence definitions there are. We have none.
0x00,
// The next value is the number of special keys. We use these.
NX_NUMSPECIALKEYS,
// Special Key SCANCODE
//-----------------------------------------------------------
NX_KEYTYPE_SOUND_UP, NX_KEYTYPE_SOUND_UP,
NX_KEYTYPE_SOUND_DOWN, NX_KEYTYPE_SOUND_DOWN,
NX_KEYTYPE_BRIGHTNESS_UP, NX_KEYTYPE_BRIGHTNESS_UP,
NX_KEYTYPE_BRIGHTNESS_DOWN, NX_KEYTYPE_BRIGHTNESS_DOWN,
NX_KEYTYPE_CAPS_LOCK, NX_KEYTYPE_CAPS_LOCK,
NX_KEYTYPE_HELP, NX_KEYTYPE_HELP,
NX_POWER_KEY, NX_POWER_KEY,
NX_KEYTYPE_MUTE, NX_KEYTYPE_MUTE,
NX_UP_ARROW_KEY, NX_UP_ARROW_KEY,
NX_DOWN_ARROW_KEY, NX_DOWN_ARROW_KEY,
NX_KEYTYPE_NUM_LOCK, NX_KEYTYPE_NUM_LOCK,
NX_KEYTYPE_CONTRAST_UP, NX_KEYTYPE_CONTRAST_UP,
NX_KEYTYPE_CONTRAST_DOWN, NX_KEYTYPE_CONTRAST_DOWN,
NX_KEYTYPE_LAUNCH_PANEL, NX_KEYTYPE_LAUNCH_PANEL,
NX_KEYTYPE_EJECT, NX_KEYTYPE_EJECT,
NX_KEYTYPE_VIDMIRROR, NX_KEYTYPE_VIDMIRROR,
NX_KEYTYPE_PLAY, NX_KEYTYPE_PLAY,
NX_KEYTYPE_NEXT, NX_KEYTYPE_NEXT,
NX_KEYTYPE_PREVIOUS, NX_KEYTYPE_PREVIOUS,
NX_KEYTYPE_FAST, NX_KEYTYPE_FAST,
NX_KEYTYPE_REWIND, NX_KEYTYPE_REWIND,
NX_KEYTYPE_ILLUMINATION_UP, NX_KEYTYPE_ILLUMINATION_UP,
NX_KEYTYPE_ILLUMINATION_DOWN, NX_KEYTYPE_ILLUMINATION_DOWN,
NX_KEYTYPE_ILLUMINATION_TOGGLE, NX_KEYTYPE_ILLUMINATION_TOGGLE
};
if( length ) *length = sizeof( ConsumerKeyMap );
return( ConsumerKeyMap );
}