init(keyboardEventSource:virtualKey:keyDown:)
Returns a new Quartz keyboard event.
Declaration
init?(keyboardEventSource source: CGEventSource?, virtualKey: CGKeyCode, keyDown: Bool)Parameters
- source:
An event source taken from another event, or
NULL. - virtualKey:
The virtual key code for the event.
- keyDown:
Pass
trueto specify that the key position is down. To specify that the key position is up, passfalse. This value is used to determine the type of the keyboard event—see Cgeventtype.
Return Value
A new keyboard event, or NULL if the event could not be created. When you no longer need the event, you should release it using the function CFRelease.
Discussion
All keystrokes needed to generate a character must be entered, including modifier keys. For example, to produce a ‘Z’, the SHIFT key must be down, the ‘z’ key must go down, and then the SHIFT and ‘z’ key must be released:
CGEventRef event1, event2, event3, event4;
event1 = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)56, true);
event2 = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)6, true);
event3 = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)6, false);
event4 = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)56, false);See Also
Functions
CGAcquireDisplayFadeReservation(_:_:)CGAssociateMouseAndMouseCursorPosition(_:)CGBeginDisplayConfiguration(_:)CGCancelDisplayConfiguration(_:)CGCaptureAllDisplays()CGCaptureAllDisplaysWithOptions(_:)CGCompleteDisplayConfiguration(_:_:)CGConfigureDisplayFadeEffect(_:_:_:_:_:_:)CGConfigureDisplayMirrorOfDisplay(_:_:_:)CGConfigureDisplayMode(_:_:_:)CGConfigureDisplayOrigin(_:_:_:_:)CGConfigureDisplayStereoOperation(_:_:_:_:)CGConfigureDisplayWithDisplayMode(_:_:_:_:)CGCursorIsDrawnInFramebuffer()CGCursorIsVisible()