Type Method


Returns a new NSEvent object describing a key event.


+ (NSEvent *)keyEventWithType:(NSEventType)type location:(NSPoint)location modifierFlags:(NSEventModifierFlags)flags timestamp:(NSTimeInterval)time windowNumber:(NSInteger)wNum context:(NSGraphicsContext *)unusedPassNil characters:(NSString *)keys charactersIgnoringModifiers:(NSString *)ukeys isARepeat:(BOOL)flag keyCode:(unsigned short)code;



One of the following event-type constants: NSKeyDown, NSKeyUp, NSFlagsChanged. If anything else is specified, an NSInternalInconsistencyException is raised.


The cursor location in the base coordinate system of the window specified by windowNum.


An integer bit field containing any of the modifier key masks described in Getting Unicode Values, combined using the C bitwise OR operator.


The time the event occurred in seconds since system startup.


An integer that identifies the window device associated with the event, which is associated with the NSWindow that will receive the event.


The display graphics context of the event.


A string of characters associated with the key event. Though most key events contain only one character, it is possible for a single keypress to generate a series of characters.


The string of characters generated by the key event as if no modifier key had been pressed (except for Shift). This argument is useful for getting the “basic” key value in a hardware-independent manner.


YES if the key event is a repeat caused by the user holding the key down, NO if the key event is new.


A number that identifies the keyboard key associated with the key event. Its value is hardware-independent.

Return Value

The created NSEvent instance or nil if the instance could not be created.

See Also

Creating Events

+ mouseEventWithType:location:modifierFlags:timestamp:windowNumber:context:eventNumber:clickCount:pressure:

Returns a new NSEvent object describing a mouse-down, -up, -moved, or -dragged event.

+ enterExitEventWithType:location:modifierFlags:timestamp:windowNumber:context:eventNumber:trackingNumber:userData:

Returns a new NSEvent object describing a tracking-rectangle or cursor-update event.

+ eventWithEventRef:

Creates an event object that is based on a Carbon type of event.

+ eventWithCGEvent:

Creates and returns an event object that is based on a Core Graphics type of event.