Re: Offtopic: simulating a keystroke

Malcolm Beattie (mbeattie@sable.ox.ac.uk)
Fri, 8 Aug 1997 11:20:16 +0100 (BST)


fb writes:
> Ok, now here's the tricky part :) How should I go about simulating a
> keystroke in a way that it will be transparent to all applications? (ie
> the program that recieves the key press will not know that its a simulated
> one)

User-mode, not kernel.
#include <sys/ioctl.h>
char ch;
ioctl(fd, TIOCSTI, &ch);
forces character ch into the input buffer provided fd refers to your
controlling terimnal (or your privileged). Quick example:

#include <sys/ioctl.h>
int main(void) {
ioctl(1, TIOCSTI, "l");
ioctl(1, TIOCSTI, "s");
ioctl(1, TIOCSTI, "\n");
return 0;
}

--Malcolm

-- 
Malcolm Beattie <mbeattie@sable.ox.ac.uk>
Unix Systems Programmer
Oxford University Computing Services