Joel P.
Joel P.

Reputation: 35

send keystroke to shell app?

I am newbie in cocoa. I am working on a GUI for a shell app. I am using AMShellWrapper class, and it works fine.

The problem is that my shell app has a dialog requests a keystroke to continue. I'm pretty lost at this point. I've tried CGEventCreateKeyboardEvent but may not be the right way.

Anyone know how I can send a keystroke to a shell app that was initiated by my wrapper?

Upvotes: 2

Views: 186

Answers (1)

sarnold
sarnold

Reputation: 104050

You can create a pty(4) pseudo-terminal in which to run the application. This allows your application to be the "master" (think Terminal.app) which runs the "slave" program (think bash(1)) and provides mechanisms to control the slave.

This is a pretty involved area of Unix programming; I strongly recommend reading the source for the pty.c program in the sourcecode for the Advanced Programming in the Unix Environment, 2nd edition book. (The source code would make a lot more sense if read with the companion chapter in the book.)

You could probably use the pty.c program unchanged and supply a 'driver' for it to drive your client program, which would simplify the task.

Upvotes: 1

Related Questions