Search code examples
objective-cnsevent

NSEvent feeding to system


Can someone show an example on how to create an NSEvent that simulates pressing return?


Solution

  • You should take a look at the NSEvent Class Reference, and more specifically, -keyEventWithType:location:modifierFlags:timestamp:windowNumber:context:characters:charactersIgnoringModifiers:isARepeat:keyCode:.

    From there, it shouldn't be difficult. Construct all the necessary components, and send the event using NSApplication's -sendEvent: method.