From here :
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
int main(void)
{
int hTTY = open("/dev/tty1", O_WRONLY|O_NONBLOCK);
ioctl(hTTY, TIOCSTI, "b");
close(hTTY);
return 0;
}
The terminal and keystroke are hardcoded in this example, but can be adapted to your needs.
You can do something like this in Perl:
perl -e '$TIOCSTI = 0x5412; $tty = "/dev/pts/1"; $char = "b"; open($fh, ">", $tty); ioctl($fh, $TIOCSTI, $char)'
I need to run any of them using sudo.
source
share