30 var _CPEventPeriodicEventPeriod = 0,
31 _CPEventPeriodicEventTimer = nil,
32 _CPEventUpperCaseRegex =
new RegExp(
"[A-Z]"),
33 _CPEventStartupMilliseconds =
new Date().getTime();
44 unsigned _modifierFlags;
45 CPTimeInterval _timestamp;
53 CPString _charactersIgnoringModifiers
66 BOOL _suppressCappuccinoCut;
67 BOOL _suppressCappuccinoPaste;
74 + (CPTimeInterval)currentTimestamp
76 return (
new Date().getTime() - _CPEventStartupMilliseconds) / 1000;
96 + (
CPEvent)keyEventWithType:(CPEventType)anEventType location:(CGPoint)aPoint modifierFlags:(
unsigned int)modifierFlags
97 timestamp:(CPTimeInterval)aTimestamp windowNumber:(
int)aWindowNumber context:(
CPGraphicsContext)aGraphicsContext
98 characters:(
CPString)characters charactersIgnoringModifiers:(
CPString)unmodCharacters isARepeat:(BOOL)repeatKey keyCode:(
unsigned short)code
100 return [[
self alloc] _initKeyEventWithType:anEventType location:aPoint modifierFlags:modifierFlags
101 timestamp:aTimestamp windowNumber:aWindowNumber context:aGraphicsContext
102 characters:characters charactersIgnoringModifiers:unmodCharacters isARepeat:repeatKey keyCode:code];
120 + (id)mouseEventWithType:(CPEventType)anEventType location:(CGPoint)aPoint modifierFlags:(
unsigned)modifierFlags
121 timestamp:(CPTimeInterval)aTimestamp windowNumber:(
int)aWindowNumber context:(
CPGraphicsContext)aGraphicsContext
122 eventNumber:(
int)anEventNumber clickCount:(
int)aClickCount pressure:(
float)aPressure
124 return [[
self alloc] _initMouseEventWithType:anEventType location:aPoint modifierFlags:modifierFlags
125 timestamp:aTimestamp windowNumber:aWindowNumber context:aGraphicsContext eventNumber:anEventNumber clickCount:aClickCount pressure:aPressure];
143 + (
CPEvent)otherEventWithType:(CPEventType)anEventType location:(CGPoint)aLocation modifierFlags:(
unsigned)modifierFlags
144 timestamp:(CPTimeInterval)aTimestamp windowNumber:(
int)aWindowNumber context:(
CPGraphicsContext)aGraphicsContext
145 subtype:(
short)aSubtype data1:(
int)aData1 data2:(
int)aData2
147 return [[
self alloc] _initOtherEventWithType:anEventType location:aLocation modifierFlags:modifierFlags
148 timestamp:aTimestamp windowNumber:aWindowNumber context:aGraphicsContext subtype:aSubtype data1:aData1 data2:aData2];
151 - (id)_initWithType:(CPEventType)anEventType
153 if (
self = [super init])
167 - (id)_initMouseEventWithType:(CPEventType)anEventType location:(CGPoint)aPoint modifierFlags:(
unsigned)modifierFlags
168 timestamp:(CPTimeInterval)aTimestamp windowNumber:(
int)aWindowNumber context:(
CPGraphicsContext)aGraphicsContext
169 eventNumber:(
int)anEventNumber clickCount:(
int)aClickCount pressure:(
float)aPressure
171 if (
self = [
self _initWithType:anEventType])
173 _location = CGPointCreateCopy(aPoint);
174 _modifierFlags = modifierFlags;
175 _timestamp = aTimestamp;
176 _context = aGraphicsContext;
177 _eventNumber = anEventNumber;
178 _clickCount = aClickCount;
179 _pressure = aPressure;
180 _window = [CPApp windowWithWindowNumber:aWindowNumber];
187 - (id)_initKeyEventWithType:(CPEventType)anEventType location:(CGPoint)aPoint modifierFlags:(
unsigned int)modifierFlags
188 timestamp:(CPTimeInterval)aTimestamp windowNumber:(
int)aWindowNumber context:(
CPGraphicsContext)aGraphicsContext
189 characters:(
CPString)characters charactersIgnoringModifiers:(
CPString)unmodCharacters isARepeat:(BOOL)isARepeat keyCode:(
unsigned short)code
191 if (
self = [
self _initWithType:anEventType])
193 _location = CGPointCreateCopy(aPoint);
194 _modifierFlags = modifierFlags;
195 _timestamp = aTimestamp;
196 _context = aGraphicsContext;
197 _characters = characters;
198 _charactersIgnoringModifiers = unmodCharacters;
199 _isARepeat = isARepeat;
201 _windowNumber = aWindowNumber;
208 - (id)_initOtherEventWithType:(CPEventType)anEventType location:(CGPoint)aPoint modifierFlags:(
unsigned)modifierFlags
209 timestamp:(CPTimeInterval)aTimestamp windowNumber:(
int)aWindowNumber context:(
CPGraphicsContext)aGraphicsContext
210 subtype:(
short)aSubtype data1:(
int)aData1 data2:(
int)aData2
212 if (
self = [
self _initWithType:anEventType])
214 _location = CGPointCreateCopy(aPoint);
215 _modifierFlags = modifierFlags;
216 _timestamp = aTimestamp;
217 _context = aGraphicsContext;
234 - (CGPoint)locationInWindow
236 return CGPointMakeCopy(_location);
239 - (CGPoint)globalLocation
241 var theWindow = [
self window],
242 location = [
self locationInWindow];
245 return [theWindow convertBaseToGlobal:location];
253 - (unsigned)modifierFlags
255 return _modifierFlags;
261 - (CPTimeInterval)timestamp
280 _window = [CPApp windowWithWindowNumber:_windowNumber];
290 return _windowNumber;
328 - (
CPString)charactersIgnoringModifiers
330 return _charactersIgnoringModifiers;
348 - (
unsigned short)keyCode
353 + (CGPoint)mouseLocation
356 var
event = [CPApp currentEvent],
357 eventWindow = [event window];
360 return [eventWindow convertBaseToGlobal:[event locationInWindow]];
362 return [event locationInWindow];
373 - (DOMEvent)_DOMEvent
413 - (BOOL)_triggersKeyEquivalent:(
CPString)aKeyEquivalent withModifierMask:aKeyEquivalentModifierMask
418 if (_CPEventUpperCaseRegex.test(aKeyEquivalent))
435 return [_characters caseInsensitiveCompare:aKeyEquivalent] ===
CPOrderedSame;
438 - (BOOL)_couldBeKeyEquivalent
443 var characterCount = _characters.length;
453 var firstResponderIsText = [[_window firstResponder] isKindOfClass:[
CPTextField class]];
457 for (var i = 0; i < characterCount; i++)
459 var c = _characters.charAt(i);
471 return !firstResponderIsText;
482 - (BOOL)_platformIsEffectingCutOrPaste
485 return _suppressCappuccinoCut || _suppressCappuccinoPaste;
498 + (void)startPeriodicEventsAfterDelay:(CPTimeInterval)aDelay withPeriod:(CPTimeInterval)aPeriod
500 _CPEventPeriodicEventPeriod = aPeriod;
503 _CPEventPeriodicEventTimer = window.setTimeout(
function() { _CPEventPeriodicEventTimer = window.setInterval(_CPEventFirePeriodEvent, aPeriod * 1000.0); }, aDelay * 1000.0);
509 + (void)stopPeriodicEvents
511 if (_CPEventPeriodicEventTimer === nil)
514 window.clearTimeout(_CPEventPeriodicEventTimer);
516 _CPEventPeriodicEventTimer = nil;
526 return [
CPString stringWithFormat:@"CPEvent: type=%d loc=%@ time=%.1f flags=0x%X win=%@ winNum=%d ctxt=%@ chars=\"%@\" unmodchars=\"%@\" repeat=%d keyCode=%d", _type, CGStringFromPoint(_location), _timestamp, _modifierFlags, _window, _windowNumber, _context, _characters, _charactersIgnoringModifiers, _isARepeat, _keyCode];
536 return [
CPString stringWithFormat:@"CPEvent: type=%d loc=%@ time=%.1f flags=0x%X win=%@ winNum=%d ctxt=%@ evNum=%d click=%d buttonNumber=%d pressure=%f", _type, CGStringFromPoint(_location), _timestamp, _modifierFlags, _window, _windowNumber, _context, _eventNumber, _clickCount, [
self buttonNumber], _pressure];
538 return [
CPString stringWithFormat:@"CPEvent: type=%d loc=%@ time=%.1f flags=0x%X win=%@ winNum=%d ctxt=%@ subtype=%d data1=%d data2=%d", _type, CGStringFromPoint(_location), _timestamp, _modifierFlags, _window, _windowNumber, _context, _subtype, _data1, _data2];
544 function _CPEventFirePeriodEvent()
546 [CPApp sendEvent:[
CPEvent otherEventWithType:CPPeriodic location:CGPointMakeZero() modifierFlags:0 timestamp:[
CPEvent currentTimestamp] windowNumber:0 context:nil subtype:0 data1:0 data2:0]];
549 var CPEventClass = [
CPEvent class];
551 function _CPEventFromNativeMouseEvent(aNativeEvent, anEventType, aPoint, modifierFlags, aTimestamp, aWindowNumber, aGraphicsContext, anEventNumber, aClickCount, aPressure)
553 aNativeEvent.isa = CPEventClass;
555 aNativeEvent._type = anEventType;
556 aNativeEvent._location = aPoint;
557 aNativeEvent._modifierFlags = modifierFlags;
558 aNativeEvent._timestamp = aTimestamp;
559 aNativeEvent._windowNumber = aWindowNumber;
560 aNativeEvent._window = nil;
561 aNativeEvent._context = aGraphicsContext;
562 aNativeEvent._eventNumber = anEventNumber;
563 aNativeEvent._clickCount = aClickCount;
564 aNativeEvent._pressure = aPressure;