I have the following Objective-C snippet:
void toggle()
{
NSEvent* down_event = [NSEvent keyEventWithType: NSEventTypeKeyDown
location: NSZeroPoint
modifierFlags: 0
timestamp: 0.0
windowNumber: 0
context: nil
characters: @" "
charactersIgnoringModifiers: @" "
isARepeat: false
keyCode: kVK_Space ];
CGEventPost(kCGHIDEventTap, [down_event CGEvent]);
}
The project is ARC enabled.
Is this safe, or am I running the gauntlet of an occasional memory access error?
I'm worried that the NSObject
may be garbage collected while the system is still making use of its CGEvent
.