OSDN Git Service

first
[psychlops/cpp.git] / psychlops / platform / osx / psychlops_io_API_OSX.cpp
1 /*
2  *  psychlops_io_API_OSX.cpp
3  *  Psychlops Standard Library (MacOSX)
4  *
5  *  Last Modified 2006/01/04 by Kenchi HOSOKAWA
6  *  (C) 2005 Kenchi HOSOKAWA, Kazushi MARUYA, Takao SATO
7  */
8
9
10 #include <Carbon/Carbon.h>
11 #include <ApplicationServices/ApplicationServices.h>
12 #include <CoreServices/CoreServices.h>
13 //#include <CoreFoundation/CoreFoundation.h>
14
15
16 #include "psychlops_io_API_OSX.h"
17 #include "../../core/devices/psychlops_io_hid.h"
18
19
20 namespace Psychlops {
21
22         typedef HumanInterfaceDevice HID;
23
24         MPTaskID APIHIDProperties::inputListnerTask, APIHIDProperties::inputListnerTask2;
25         bool APIHIDProperties::refresh_needed = false;
26
27         void APIHIDProperties::initialize() {
28                 bindKeyCode();
29         }
30         void APIHIDProperties::finalize() {
31         }
32         bool APIHIDProperties::get(Mouse::Button button, Mouse::ButtonState state) {
33                 bool val = HID::state[state].button[button.code];
34                 if(state!=Mouse::pressed) HID::state[state].button[button.code] = false;
35                 return val;
36         }
37         void APIHIDProperties::setPointerPosition(int x, int y) {
38                 CGPoint p;
39                 p.x = x;
40                 p.y = y;
41                 CGWarpMouseCursorPosition(p);
42         }
43
44 #if (defined(PANTHER) && ( PANTHER==1 )) || defined(PSYCHLOPS_SNOW_LEOPARD_PATCH)
45         const int KEYMAP_ARRAY_LENGTH = 4;
46         void APIHIDProperties::updateKeyboard() {
47                 KeyMap tmpkeys;
48                 for(int i=0;i<KEYMAP_ARRAY_LENGTH;i++) {
49                         key[HID::hadpressed][i] = key[HID::pressed][i];
50                 }
51                 GetKeys(tmpkeys);
52 #if (__LITTLE_ENDIAN__)
53                 for(int i=0; i<4; i++) key[HID::pressed][i] = CFSwapInt32BigToHost( tmpkeys[i].bigEndianValue );
54 #else
55                 for(int i=0; i<4; i++) key[HID::pressed][i] = tmpkeys[i];
56 #endif
57                 for(int i=0;i<KEYMAP_ARRAY_LENGTH;i++) {
58                         key[HID::pushed][i] = (key[HID::pressed][i] ^ key[HID::hadpressed][i]) & key[HID::pressed][i] | key[HID::pushed][i];
59                         key[HID::released][i] = (key[HID::pressed][i] ^ key[HID::hadpressed][i]) & (~key[HID::pressed][i]) | key[HID::released][i];
60                 }
61         }
62         void APIHIDProperties::updateMouse() {
63                 bool state = Button();
64                 HID::state[HID::hadpressed].button[Mouse::left.code] = HID::state[HID::pressed].button[Mouse::left.code];               
65                 HID::state[HID::pressed].button[Mouse::left.code] = state;
66                 HID::state[HID::pushed].button[Mouse::left.code] = (HID::state[HID::pressed].button[Mouse::left.code] != HID::state[HID::hadpressed].button[Mouse::left.code]) & HID::state[HID::pressed].button[Mouse::left.code] | HID::state[HID::pushed].button[Mouse::left.code];
67                 HID::state[HID::released].button[Mouse::left.code] = (HID::state[HID::pressed].button[Mouse::left.code] != HID::state[HID::hadpressed].button[Mouse::left.code]) & !HID::state[HID::pressed].button[Mouse::left.code] | HID::state[HID::released].button[Mouse::left.code];
68                 ::Point point;
69                 GetMouse(&point);
70                 Mouse::uniX.val_ = point.h;
71                 Mouse::uniY.val_ = point.v;
72         }
73         
74         //      UInt32 APIKeyboardProperties::TMP_KEY_STATUS = 0;
75         UInt32 APIHIDProperties::key[KEYMAP_ARRAY_LENGTH][4];
76         unsigned long APIHIDProperties::keybinder[128][2];
77
78         void APIHIDProperties::refresh() {
79                 for(int i=0;i<KEYMAP_ARRAY_LENGTH;i++) {
80                         key[HID::pushed][i] = 0;
81                         key[HID::released][i] = 0;
82                 }
83                 refresh_needed = false;
84         }               
85         
86 #endif
87
88 #if defined(PANTHER) && ( PANTHER==1 )
89 //  Loop Based Keyboard-Accept Code (10.3)
90         void APIHIDProperties::startListener() {
91                 MPCreateTask((TaskProc)&lisnerProcedure, NULL, 4096, NULL, NULL, NULL, 0, &inputListnerTask);
92                 MPSetTaskWeight(inputListnerTask,1);
93         }
94         void APIHIDProperties::stopListener() {
95                 OSStatus terminationStatus = 1000;
96                 MPTerminateTask(inputListnerTask, terminationStatus);
97         }
98         void APIHIDProperties::lisnerProcedure(){
99                 MPSemaphoreID delay;
100                 MPCreateSemaphore(0, 0, &delay);
101                 for(;;) {
102                         update();
103                         (void) MPWaitOnSemaphore(delay, kDurationMicrosecond*100);
104                 }
105         }
106
107         bool APIHIDProperties::get(Keyboard::Key key_, Keyboard::KeyState state) {
108                 if(refresh_needed) { refresh(); }
109                 int returnvalue;
110                 returnvalue = key[state][keybinder[key_.code][BIG]] & keybinder[key_.code][SMALL];
111                 /*if(state!=pressed) {
112                  key[state][keybinder[code][BIG]] = key[state][keybinder[code][BIG]] & (!keybinder[code][SMALL]);
113                  }*/
114                 if(returnvalue!=0 && state!=Keyboard::pressed) {
115                         key[state][keybinder[key_.code][BIG]] -= (keybinder[key_.code][SMALL]);
116                 }
117                 if(returnvalue==0) { return false; }
118                 else { return true; }
119         }       
120         void APIHIDProperties::update() {
121                 updateKeyboard();
122                 updateMouse();
123         }
124 #else
125         
126 #if defined(PSYCHLOPS_SNOW_LEOPARD_PATCH)
127         void APIHIDProperties::lisnerProcedure(){
128                 MPSemaphoreID delay;
129                 MPCreateSemaphore(0, 0, &delay);
130                 for(;;) {
131                         updateKeyboard();
132                         (void) MPWaitOnSemaphore(delay, kDurationMicrosecond*1000);
133                 }
134         }
135         bool APIHIDProperties::get(Keyboard::Key key_, Keyboard::KeyState state) {
136                 if(refresh_needed) { refresh(); }
137                 int returnvalue;
138                 returnvalue = key[state][keybinder[key_.code][BIG]] & keybinder[key_.code][SMALL];
139                 if(returnvalue!=0 && state!=Keyboard::pressed) key[state][keybinder[key_.code][BIG]] -= (keybinder[key_.code][SMALL]);
140                 return returnvalue==0 ? false : true;
141         }
142 #else
143 //  Event Based Keyboard-Accept Code (10.4)
144         bool APIHIDProperties::get(Keyboard::Key key_, Keyboard::KeyState state) {
145                 bool val = HID::state[(HID::ButtonState)state].key[keybinder[key_.code]];
146                 if(state!=Keyboard::pressed) HID::state[(HID::ButtonState)state].key[keybinder[key_.code]] = false;
147                 return val;
148         }
149 #endif
150
151         void APIHIDProperties::update() {
152         }
153
154         void APIHIDProperties::startListener() {
155                 MPCreateTask((TaskProc)&loopListener, NULL, 4096, NULL, NULL, NULL, 0, &inputListnerTask);
156                 MPSetTaskWeight(inputListnerTask,1);
157 #if defined(PSYCHLOPS_SNOW_LEOPARD_PATCH)
158                 MPCreateTask((TaskProc)&lisnerProcedure, NULL, 4096, NULL, NULL, NULL, 0, &inputListnerTask);
159                 MPSetTaskWeight(inputListnerTask2,1);
160 #endif
161         }
162         void APIHIDProperties::stopListener() {
163                 OSStatus terminationStatus = 1000;
164                 MPTerminateTask(inputListnerTask, terminationStatus);
165 #if !defined(PSYCHLOPS_SNOW_LEOPARD_PATCH)
166                 CFRelease(listenerKey);
167 #else
168                 MPTerminateTask(inputListnerTask2, terminationStatus);
169 #endif
170                 CFRelease(listenerMouse);
171         }
172         void APIHIDProperties::loopListener() {
173 #if !defined(PSYCHLOPS_SNOW_LEOPARD_PATCH)
174                 CGEventMask keyMask   = CGEventMaskBit(kCGEventKeyDown) | CGEventMaskBit(kCGEventKeyUp) | CGEventMaskBit(kCGEventFlagsChanged);
175                 //ProcessSerialNumber psn;
176                 //GetCurrentProcess(&psn);
177                 //CFMachPortRef tapKey   = CGEventTapCreateForPSN(&psn, kCGTailAppendEventTap, kCGEventTapOptionListenOnly, keyMask, &listenToKeyboard, NULL);
178                 CFMachPortRef tapKey   = CGEventTapCreate(/*kCGAnnotatedSessionEventTap*/kCGHIDEventTap, kCGTailAppendEventTap, kCGEventTapOptionListenOnly, keyMask, &listenToKeyboard, NULL);
179                 listenerKey = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, tapKey, 0);
180                 CFRunLoopAddSource(CFRunLoopGetCurrent(), listenerKey, kCFRunLoopCommonModes);
181 #endif
182                 CGEventMask mouseMask =
183                 CGEventMaskBit(kCGEventLeftMouseDown)  | CGEventMaskBit(kCGEventLeftMouseUp) | CGEventMaskBit(kCGEventLeftMouseDragged)
184                 | CGEventMaskBit(kCGEventRightMouseDown)   | CGEventMaskBit(kCGEventRightMouseUp) | CGEventMaskBit(kCGEventRightMouseDragged)
185                 | CGEventMaskBit(kCGEventOtherMouseDown) | CGEventMaskBit(kCGEventOtherMouseUp) | CGEventMaskBit(kCGEventOtherMouseDragged)
186                 | CGEventMaskBit(kCGEventMouseMoved)     | CGEventMaskBit(kCGEventScrollWheel);
187                 //CFMachPortRef tapMouse = CGEventTapCreateForPSN(&psn, kCGTailAppendEventTap, kCGEventTapOptionListenOnly, mouseMask, &listenToMouse, NULL);
188                 CFMachPortRef tapMouse = CGEventTapCreate(kCGAnnotatedSessionEventTap, kCGTailAppendEventTap, kCGEventTapOptionListenOnly, mouseMask, &listenToMouse, NULL);
189                 listenerMouse = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, tapMouse, 0);
190                 CFRunLoopAddSource(CFRunLoopGetCurrent(), listenerMouse, kCFRunLoopCommonModes);
191
192                 CFRunLoopRun();
193         }
194         CGEventRef APIHIDProperties::listenToKeyboard(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) {
195 #if !defined(PSYCHLOPS_SNOW_LEOPARD_PATCH)
196                 CGEventFlags flags = CGEventGetFlags(event);
197                 CGPoint point = CGEventGetLocation(event);
198                 CGEventTimestamp time_stamp = CGEventGetTimestamp(event);
199                 int64_t key_code = CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode);
200                 bool tmp_mod;
201
202                 switch (type) {
203                         case kCGEventKeyDown:
204                                 HID::state[HID::pressed].key[key_code] = true;
205                                 HID::state[HID::pushed].key[key_code] = true | HID::state[HID::pushed].key[key_code];
206                                 break;
207                         case kCGEventKeyUp:
208                                 HID::state[HID::pressed].key[key_code] = true;
209                                 HID::state[HID::released].key[key_code] = true | HID::state[HID::released].key[key_code];
210                                 break;
211                         case kCGEventFlagsChanged:
212                                 const CGEventFlags flags = CGEventSourceFlagsState(kCGEventSourceStateCombinedSessionState);
213                                 tmp_mod = HID::state[HID::pressed].key[keybinder[Keyboard::shift.code]];
214                                 HID::state[HID::pressed].key[keybinder[Keyboard::shift.code]] = ((flags&kCGEventFlagMaskShift)!=0);
215                                 if((flags&kCGEventFlagMaskShift)!=0) HID::state[HID::pushed].key[keybinder[Keyboard::shift.code]] = true | HID::state[HID::pushed].key[keybinder[Keyboard::shift.code]];
216                                 HID::state[HID::pressed].key[keybinder[Keyboard::ctrl.code]]  = ((flags&kCGEventFlagMaskControl)!=0);
217                                 if((flags&kCGEventFlagMaskControl)!=0) HID::state[HID::pushed].key[keybinder[Keyboard::ctrl.code]] = true | HID::state[HID::pushed].key[keybinder[Keyboard::ctrl.code]];
218                                 HID::state[HID::pressed].key[keybinder[Keyboard::alt.code]]   = ((flags&kCGEventFlagMaskAlternate)!=0);
219                                 if((flags&kCGEventFlagMaskAlternate)!=0) HID::state[HID::pushed].key[keybinder[Keyboard::alt.code]] = true | HID::state[HID::pushed].key[keybinder[Keyboard::alt.code]];
220                                 break;
221                 }
222 #endif
223                 if(refresh_needed) {
224                         Keyboard::refresh_internal();
225                         Mouse::refresh_internal();
226                         refresh_needed = false;
227                 }
228                 return NULL;
229         }
230         CGEventRef APIHIDProperties::listenToMouse(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) {
231                 CGEventFlags flags = CGEventGetFlags(event);
232                 CGPoint point = CGEventGetLocation(event);
233                 CGEventTimestamp time_stamp = CGEventGetTimestamp(event);
234                 //Mouse::lastPoint.x = point.x; Mouse::lastPoint.y = point.y;
235                 Mouse::uniX.val_ = point.x;
236                 Mouse::uniY.val_ = point.y;
237                 if(type==kCGEventMouseMoved) return NULL;
238                 if(type==kCGEventScrollWheel) {
239                         Mouse::wheelDelta.y -= CGEventGetIntegerValueField(event, kCGScrollWheelEventDeltaAxis1);
240                         Mouse::wheelDelta.x -= CGEventGetIntegerValueField(event, kCGScrollWheelEventDeltaAxis2);
241                         Mouse::wheelDelta.z += CGEventGetIntegerValueField(event, kCGScrollWheelEventDeltaAxis3);
242                         return NULL;
243                 }
244                 int button = CGEventGetIntegerValueField(event, kCGMouseEventButtonNumber);
245                 switch (type) {
246                         case kCGEventLeftMouseDown:
247                         case kCGEventRightMouseDown:
248                         case kCGEventOtherMouseDown:
249                                 HID::state[HID::pressed].button[button] = true;
250                                 HID::state[HID::pushed].button[button] = true | HID::state[HID::pushed].button[button];
251                                 break;
252                         case kCGEventLeftMouseUp:
253                         case kCGEventRightMouseUp:
254                         case kCGEventOtherMouseUp:
255                                 HID::state[HID::pressed].button[button] = false;
256                                 HID::state[HID::released].button[button] = true | HID::state[HID::released].button[button];
257                                 break;
258                 }
259                                 /*
260                 switch (type) {
261                         case kCGEventLeftMouseDown:
262                                 HID::state[HID::pressed].button[Mouse::left.code] = true;
263                                 HID::state[HID::pushed].button[Mouse::left.code] = true | HID::state[HID::pushed].button[Mouse::left.code];
264                                 break;
265                         case kCGEventLeftMouseUp:
266                                 HID::state[HID::pressed].button[Mouse::left.code] = false;
267                                 HID::state[HID::released].button[Mouse::left.code] = true | HID::state[HID::released].button[Mouse::left.code];
268                                 break;
269                         case kCGEventRightMouseDown:
270                                 HID::state[HID::pressed].button[Mouse::right.code] = true;
271                                 HID::state[HID::pushed].button[Mouse::right.code] = true | HID::state[HID::pushed].button[Mouse::right.code];
272                                 break;
273                         case kCGEventRightMouseUp:
274                                 HID::state[HID::pressed].button[Mouse::right.code] = false;
275                                 HID::state[HID::released].button[Mouse::right.code] = true | HID::state[HID::released].button[Mouse::right.code];
276                                 break;
277                         case kCGEventOtherMouseDown:
278                                 HID::state[HID::pressed].button[Mouse::middle.code] = true;
279                                 HID::state[HID::pushed].button[Mouse::middle.code] = true | HID::state[HID::pushed].button[Mouse::middle.code];
280                                 break;
281                         case kCGEventOtherMouseUp:
282                                 HID::state[HID::pressed].button[Mouse::middle.code] = false;
283                                 HID::state[HID::released].button[Mouse::middle.code] = true | HID::state[HID::released].button[Mouse::middle.code];
284                                 break;
285                 }
286  */
287                 return NULL;
288         }
289
290         CFRunLoopSourceRef APIHIDProperties::listenerKey,  APIHIDProperties::listenerMouse;
291
292 #if !defined(PSYCHLOPS_SNOW_LEOPARD_PATCH)
293         int APIHIDProperties::keybinder[128];
294 #endif
295 #endif
296
297         void APIHIDProperties::bindKeyCode() {
298                 struct Keyboard_ {
299                         enum KeyCode{
300                                 one=0,two,three,four,five,six,seven,eight,nine,zero,
301                                 a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,
302                                 comma,period,slash,
303                                 pad0,pad1,pad2,pad3,pad4,pad5,pad6,pad7,pad8,pad9,
304                                 rtn,spc,esc,tab,up,down,left,right,
305                                 //      key modulator
306                                 shift=100, shift_r, ctrl, alt,
307                                 //  not recommended
308                                 hyphen=59,equal,backslash,caret,
309                                 underscore,semicolon,colon,leftbracket,rightbracket,at,   // because these keys laid on different location in differnt keyboard-lacalization.
310                                 padcomma,padperiod,padenter,padplus,padminus,padasterisk,padslash,padequal,padclear,    //  because these keys are OS-specific.
311                                 nfer,xfer   // because these keys exist only on Japanese keyboard
312                         };
313                 };
314
315 #if (defined(PANTHER) && ( PANTHER==1 )) || defined(PSYCHLOPS_SNOW_LEOPARD_PATCH)
316                 keybinder[Keyboard_::pad0][BIG] = 2;
317                 keybinder[Keyboard_::pad0][SMALL] = 1024;
318                 keybinder[Keyboard_::pad1][BIG] = 2;
319                 keybinder[Keyboard_::pad1][SMALL] = 2048;
320                 keybinder[Keyboard_::pad2][BIG] = 2;
321                 keybinder[Keyboard_::pad2][SMALL] = 4096;
322                 keybinder[Keyboard_::pad3][BIG] = 2;
323                 keybinder[Keyboard_::pad3][SMALL] = 8192;
324                 keybinder[Keyboard_::pad4][BIG] = 2;
325                 keybinder[Keyboard_::pad4][SMALL] = 16384;
326                 keybinder[Keyboard_::pad5][BIG] = 2;
327                 keybinder[Keyboard_::pad5][SMALL] = 32768;
328                 keybinder[Keyboard_::pad6][BIG] = 2;
329                 keybinder[Keyboard_::pad6][SMALL] = 1;
330                 keybinder[Keyboard_::pad7][BIG] = 2;
331                 keybinder[Keyboard_::pad7][SMALL] = 2;
332                 keybinder[Keyboard_::pad8][BIG] = 2;
333                 keybinder[Keyboard_::pad8][SMALL] = 8;
334                 keybinder[Keyboard_::pad9][BIG] = 2;
335                 keybinder[Keyboard_::pad9][SMALL] = 16;
336                 keybinder[Keyboard_::padcomma][BIG] = 2;
337                 keybinder[Keyboard_::padcomma][SMALL] = 128;
338                 keybinder[Keyboard_::padperiod][BIG] = 2;
339                 keybinder[Keyboard_::padperiod][SMALL] = 33554432L;
340                 keybinder[Keyboard_::padenter][BIG] = 2;
341                 keybinder[Keyboard_::padenter][SMALL] = 1048576L;
342                 keybinder[Keyboard_::padplus][BIG] = 2;
343                 keybinder[Keyboard_::padplus][SMALL] = 536870912L;
344                 keybinder[Keyboard_::padminus][BIG] = 2;
345                 keybinder[Keyboard_::padminus][SMALL] = 4194304L;
346                 keybinder[Keyboard_::padasterisk][BIG] = 2;
347                 keybinder[Keyboard_::padasterisk][SMALL] = 134217728L;
348                 keybinder[Keyboard_::padslash][BIG] = 2;
349                 keybinder[Keyboard_::padslash][SMALL] = 524288;
350                 keybinder[Keyboard_::padequal][BIG] = 2;
351                 keybinder[Keyboard_::padequal][SMALL] = 512;
352                 keybinder[Keyboard_::padclear][BIG] = 2;
353                 keybinder[Keyboard_::padclear][SMALL] = 2147483648UL;
354                 
355                 keybinder[Keyboard_::one][BIG] = 0;
356                 keybinder[Keyboard_::one][SMALL] = 1024;
357                 keybinder[Keyboard_::two][BIG] = 0;
358                 keybinder[Keyboard_::two][SMALL] = 2048;
359                 keybinder[Keyboard_::three][BIG] = 0;
360                 keybinder[Keyboard_::three][SMALL] = 4096;
361                 keybinder[Keyboard_::four][BIG] = 0;
362                 keybinder[Keyboard_::four][SMALL] = 8192;
363                 keybinder[Keyboard_::five][BIG] = 0;
364                 keybinder[Keyboard_::five][SMALL] = 32768;
365                 keybinder[Keyboard_::six][BIG] = 0;
366                 keybinder[Keyboard_::six][SMALL] = 16384;
367                 keybinder[Keyboard_::seven][BIG] = 0;
368                 keybinder[Keyboard_::seven][SMALL] = 4;
369                 keybinder[Keyboard_::eight][BIG] = 0;
370                 keybinder[Keyboard_::eight][SMALL] = 16;
371                 keybinder[Keyboard_::nine][BIG] = 0;
372                 keybinder[Keyboard_::nine][SMALL] = 2;
373                 keybinder[Keyboard_::zero][BIG] = 0;
374                 keybinder[Keyboard_::zero][SMALL] = 32;
375                 keybinder[Keyboard_::hyphen][BIG] = 0;
376                 keybinder[Keyboard_::hyphen][SMALL] = 8;
377                 keybinder[Keyboard_::caret][BIG] = 0;
378                 keybinder[Keyboard_::caret][SMALL] = 1;
379                 keybinder[Keyboard_::backslash][BIG] = 2;
380                 keybinder[Keyboard_::backslash][SMALL] = 32;
381                 
382                 keybinder[Keyboard_::q][BIG] = 0;
383                 keybinder[Keyboard_::q][SMALL] = 1048576L;
384                 keybinder[Keyboard_::w][BIG] = 0;
385                 keybinder[Keyboard_::w][SMALL] = 2097152L;
386                 keybinder[Keyboard_::e][BIG] = 0;
387                 keybinder[Keyboard_::e][SMALL] = 4194304L;
388                 keybinder[Keyboard_::r][BIG] = 0;
389                 keybinder[Keyboard_::r][SMALL] = 8388608L;
390                 keybinder[Keyboard_::t][BIG] = 0;
391                 keybinder[Keyboard_::t][SMALL] = 512;
392                 keybinder[Keyboard_::y][BIG] = 0;
393                 keybinder[Keyboard_::y][SMALL] = 256;
394                 keybinder[Keyboard_::u][BIG] = 1;
395                 keybinder[Keyboard_::u][SMALL] = 16777216L;
396                 keybinder[Keyboard_::i][BIG] = 1;
397                 keybinder[Keyboard_::i][SMALL] = 67108864L;
398                 keybinder[Keyboard_::o][BIG] = 0;
399                 keybinder[Keyboard_::o][SMALL] = 128;
400                 keybinder[Keyboard_::p][BIG] = 1;
401                 keybinder[Keyboard_::p][SMALL] = 134217728L;
402                 keybinder[Keyboard_::at][BIG] = 1;
403                 keybinder[Keyboard_::at][SMALL] = 33554432L;
404                 keybinder[Keyboard_::leftbracket][BIG] = 0;
405                 keybinder[Keyboard_::leftbracket][SMALL] = 64;
406                 
407                 keybinder[Keyboard_::a][BIG] = 0;
408                 keybinder[Keyboard_::a][SMALL] = 16777216L;
409                 keybinder[Keyboard_::s][BIG] = 0;
410                 keybinder[Keyboard_::s][SMALL] = 33554432L;
411                 keybinder[Keyboard_::d][BIG] = 0;
412                 keybinder[Keyboard_::d][SMALL] = 67108864L;
413                 keybinder[Keyboard_::f][BIG] = 0;
414                 keybinder[Keyboard_::f][SMALL] = 134217728L;
415                 keybinder[Keyboard_::g][BIG] = 0;
416                 keybinder[Keyboard_::g][SMALL] = 536870912L;
417                 keybinder[Keyboard_::h][BIG] = 0;
418                 keybinder[Keyboard_::h][SMALL] = 268435456L;
419                 keybinder[Keyboard_::j][BIG] = 1;
420                 keybinder[Keyboard_::j][SMALL] = 1073741824L;
421                 keybinder[Keyboard_::k][BIG] = 1;
422                 keybinder[Keyboard_::k][SMALL] = 65536L;
423                 keybinder[Keyboard_::l][BIG] = 1;
424                 keybinder[Keyboard_::l][SMALL] = 536870912L;
425                 keybinder[Keyboard_::semicolon][BIG] = 1;
426                 keybinder[Keyboard_::semicolon][SMALL] = 131072L;
427                 keybinder[Keyboard_::colon][BIG] = 1;
428                 keybinder[Keyboard_::colon][SMALL] = 2147483648UL;
429                 keybinder[Keyboard_::rightbracket][BIG] = 1;
430                 keybinder[Keyboard_::rightbracket][SMALL] = 262144L;
431                 
432                 keybinder[Keyboard_::z][BIG] = 0;
433                 keybinder[Keyboard_::z][SMALL] = 1073741824L;
434                 keybinder[Keyboard_::x][BIG] = 0;
435                 keybinder[Keyboard_::x][SMALL] = 2147483648UL;
436                 keybinder[Keyboard_::c][BIG] = 0;
437                 keybinder[Keyboard_::c][SMALL] = 65536L;
438                 keybinder[Keyboard_::v][BIG] = 0;
439                 keybinder[Keyboard_::v][SMALL] = 131072L;
440                 keybinder[Keyboard_::b][BIG] = 0;
441                 keybinder[Keyboard_::b][SMALL] = 524288L;
442                 keybinder[Keyboard_::n][BIG] = 1;
443                 keybinder[Keyboard_::n][SMALL] = 2097152L;
444                 keybinder[Keyboard_::m][BIG] = 1;
445                 keybinder[Keyboard_::m][SMALL] = 4194304L;
446                 keybinder[Keyboard_::comma][BIG] = 1;
447                 keybinder[Keyboard_::comma][SMALL] = 524288L;
448                 keybinder[Keyboard_::period][BIG] = 1;
449                 keybinder[Keyboard_::period][SMALL] = 8388608L;
450                 keybinder[Keyboard_::slash][BIG] = 1;
451                 keybinder[Keyboard_::slash][SMALL] = 1048576L;
452                 keybinder[Keyboard_::underscore][BIG] = 2;
453                 keybinder[Keyboard_::underscore][SMALL] = 64;
454                 
455                 keybinder[Keyboard_::esc][BIG] = 1;
456                 keybinder[Keyboard_::esc][SMALL] = 8192;
457                 keybinder[Keyboard_::tab][BIG] = 1;
458                 keybinder[Keyboard_::tab][SMALL] = 256;
459                 keybinder[Keyboard_::rtn][BIG] = 1;
460                 keybinder[Keyboard_::rtn][SMALL] = 268435456;
461                 keybinder[Keyboard_::spc][BIG] = 1;
462                 keybinder[Keyboard_::spc][SMALL] = 512;
463                 keybinder[Keyboard_::up][BIG] = 3;
464                 keybinder[Keyboard_::up][SMALL] = 64;
465                 keybinder[Keyboard_::down][BIG] = 3;
466                 keybinder[Keyboard_::down][SMALL] = 32;
467                 keybinder[Keyboard_::left][BIG] = 3;
468                 keybinder[Keyboard_::left][SMALL] = 8;
469                 keybinder[Keyboard_::right][BIG] = 3;
470                 keybinder[Keyboard_::right][SMALL] = 16;
471                 
472                 keybinder[Keyboard_::shift][BIG] = 1;
473                 keybinder[Keyboard_::shift][SMALL] = 1;
474                 keybinder[Keyboard_::ctrl][BIG] = 1;
475                 keybinder[Keyboard_::ctrl][SMALL] = 8;
476                 keybinder[Keyboard_::alt][BIG] = 1;
477                 keybinder[Keyboard_::alt][SMALL] = 4;
478 #else
479                 keybinder[Keyboard_::pad0] = 82;
480                 keybinder[Keyboard_::pad1] = 83;
481                 keybinder[Keyboard_::pad2] = 84;
482                 keybinder[Keyboard_::pad3] = 85;
483                 keybinder[Keyboard_::pad4] = 86;
484                 keybinder[Keyboard_::pad5] = 87;
485                 keybinder[Keyboard_::pad6] = 88;
486                 keybinder[Keyboard_::pad7] = 89;
487                 keybinder[Keyboard_::pad8] = 91;
488                 keybinder[Keyboard_::pad9] = 02;
489                 keybinder[Keyboard_::padcomma] = 95;
490                 keybinder[Keyboard_::padperiod] = 65;
491                 keybinder[Keyboard_::padenter] = 76;
492                 keybinder[Keyboard_::padplus] = 69;
493                 keybinder[Keyboard_::padminus] = 78;
494                 keybinder[Keyboard_::padasterisk] = 67;
495                 keybinder[Keyboard_::padslash] = 75;
496                 keybinder[Keyboard_::padequal] = 81;
497                 keybinder[Keyboard_::padclear] = 71;
498                 
499                 keybinder[Keyboard_::one]   = 18;
500                 keybinder[Keyboard_::two]   = 19;
501                 keybinder[Keyboard_::three] = 20;
502                 keybinder[Keyboard_::four]  = 21;
503                 keybinder[Keyboard_::five]  = 23;
504                 keybinder[Keyboard_::six]   = 22;
505                 keybinder[Keyboard_::seven] = 26;
506                 keybinder[Keyboard_::eight] = 28;
507                 keybinder[Keyboard_::nine]  = 25;
508                 keybinder[Keyboard_::zero]  = 29;
509                 keybinder[Keyboard_::hyphen] = 27;
510                 keybinder[Keyboard_::caret] = 24;
511                 keybinder[Keyboard_::backslash] = 93;
512                 
513                 keybinder[Keyboard_::q] = 12;
514                 keybinder[Keyboard_::w] = 13;
515                 keybinder[Keyboard_::e] = 14;
516                 keybinder[Keyboard_::r] = 15;
517                 keybinder[Keyboard_::t] = 17;
518                 keybinder[Keyboard_::y] = 16;
519                 keybinder[Keyboard_::u] = 32;
520                 keybinder[Keyboard_::i] = 34;
521                 keybinder[Keyboard_::o] = 31;
522                 keybinder[Keyboard_::p] = 35;
523                 keybinder[Keyboard_::at] = 33;
524                 keybinder[Keyboard_::leftbracket] = 30;
525                 
526                 keybinder[Keyboard_::a] = 0;
527                 keybinder[Keyboard_::s] = 1;
528                 keybinder[Keyboard_::d] = 2;
529                 keybinder[Keyboard_::f] = 3;
530                 keybinder[Keyboard_::g] = 5;
531                 keybinder[Keyboard_::h] = 4;
532                 keybinder[Keyboard_::j] = 38;
533                 keybinder[Keyboard_::k] = 40;
534                 keybinder[Keyboard_::l] = 37;
535                 keybinder[Keyboard_::semicolon] = 41;
536                 keybinder[Keyboard_::colon] = 39;
537                 keybinder[Keyboard_::rightbracket] = 42;
538                 
539                 keybinder[Keyboard_::z] = 6;
540                 keybinder[Keyboard_::x] = 7;
541                 keybinder[Keyboard_::c] = 8;
542                 keybinder[Keyboard_::v] = 9;
543                 keybinder[Keyboard_::b] = 11;
544                 keybinder[Keyboard_::n] = 45;
545                 keybinder[Keyboard_::m] = 46;
546                 keybinder[Keyboard_::comma] = 43;
547                 keybinder[Keyboard_::period] = 47;
548                 keybinder[Keyboard_::slash] = 44;
549                 keybinder[Keyboard_::underscore] = 94;
550                 
551                 keybinder[Keyboard_::esc] = 53;
552                 keybinder[Keyboard_::rtn] = 36;
553                 keybinder[Keyboard_::spc] = 49;
554                 keybinder[Keyboard_::up] = 126;
555                 keybinder[Keyboard_::down] = 125;
556                 keybinder[Keyboard_::left] = 123;
557                 keybinder[Keyboard_::right] = 124;
558                 keybinder[Keyboard_::tab] = 48;
559                 keybinder[Keyboard_::nfer] = 102;
560                 keybinder[Keyboard_::xfer] = 104;
561
562                 keybinder[Keyboard_::shift] = 56;
563                 keybinder[Keyboard_::shift_r] = 60;
564                 keybinder[Keyboard_::ctrl] = 59;
565                 keybinder[Keyboard_::alt] = 58;
566 #endif
567         }
568
569
570
571
572
573
574
575 /*
576         ::Point APIMouseProperties::position_;
577
578         void APIMouseProperties::getPosition(int &x, int &y) {
579                 x = position_.h;
580                 y = position_.v;
581         }
582         void APIMouseProperties::setPosition(int x, int y) {
583                 CGPoint p;
584                 p.x = x;
585                 p.y = y;
586                 CGWarpMouseCursorPosition(p);
587         }
588
589         void APIMouseProperties::update() {
590                 bool state = Button();
591                 HID::state[HID::hadpressed].button[Mouse::left.code] = HID::state[HID::pressed].button[Mouse::left.code];               
592                 HID::state[HID::pressed].button[Mouse::left.code] = state;
593                 HID::state[HID::pushed].button[Mouse::left.code] = (HID::state[HID::pressed].button[Mouse::left.code] != HID::state[HID::hadpressed].button[Mouse::left.code]) & HID::state[HID::pressed].button[Mouse::left.code] | HID::state[HID::pushed].button[Mouse::left.code];
594                 HID::state[HID::released].button[Mouse::left.code] = (HID::state[HID::pressed].button[Mouse::left.code] != HID::state[HID::hadpressed].button[Mouse::left.code]) & !HID::state[HID::pressed].button[Mouse::left.code] | HID::state[HID::released].button[Mouse::left.code];
595                 GetMouse(&position_);
596         }
597
598         bool APIMouseProperties::get(Mouse::Button button, HID::ButtonState state) {
599                 bool val = HID::state[state].button[button.code];
600                 HID::state[state].button[button.code] = false;
601                 return val;
602         }
603 */
604
605 }       /*      <- namespace Psycholops         */