>Can somebody explain me, how i can send a keysequenz from a own c
>programm to another programm which is waiting for a keypress of a user..
>In example..
>I've the programm CTHUGHA, which you must use over your keyboard, by
>pressing several keys. Now i wonna write a programm, were you press a
>key on a midikeybnboard. my programm convert this key to a possible
>cthugha command. but how can i say to cthugha , that there is a key
>pressed.. ?
A possible solution would be to open a pipe, fork() spawn cthugha from your
program. Your program would then read the keyboard, do the conversion and
send it over the pipe. (e.g. you would redirect cthugha's input). If however
cthugha requires a real tty (some full-screen programs require one), you may
need to open a pty-ttyp pair, and launch cthugha from there. I think you'll
need the latter one, this can be done this way:
first try to open each /dev/ptyp* device until you find one free (e.g. the
open call succeeds), as you find one, fork(), in the child process close
0, 1, 2 (stdin, stdout, stderr) descriptors, and open /dev/ttyp* (where *
matches * after the successfully opened ptyp0 device), then execl cthugha.
Now your parent process must make a select(), one input source is /dev/ptyp*
where you may read the characters written by cthugha, these should be written
to your standard output, the other input source is your own stdin, and the
characters you read from there should be written to /dev/ptyp*. During this
copy loop, you can do the conversion.
--- Bazsi
* Author of Turbo Vision Resource WorkShop, http://www.bitsoft.com/tvrw