simulate a press key

Discussion in 'Mac Programming' started by stejano, Sep 6, 2008.

  1. macrumors newbie

    Sep 6, 2008
    This is my first thread! I'm Stejano and I hope I can help you and you can help me.
    I want to try to simulate an event key of a pression of key of my keyboard.
    I've found how to "read" the pression of a button (NSEvent) but I don't find how simulate the pression of a keyboard's key.
    How can I do?I use cocoa.

  2. macrumors 601


    Jan 6, 2004
    Western US
    I don't know of a way you can do that directly in Cocoa if you mean a true simulation of the user pressing a key anywhere in an app. You could maybe fake it by constructing and sending keyboard events to whichever view/window the user has active (like the current "key" window). Of course that will only work inside your own application, not in another or in the Finder. You might also be able to use AppleScript to do it.

Share This Page