Skip to content

Sending an arrow key with fprintf

I’m testing out pipes and have hit a little road block.

I want to be able to simulate pressing the right arrow key through a file pointer opened by popen. The file pointer opens a display program on a different terminal, much like a projector. I would like to send a signal to advance the next image (the right arrow key).

How do I go about sending this signal? I realize this will be specific to my computer (BOIS/keyboard setup), but I’m not looking for this to be portable in anyway.

It seems from my trials, everything I send via fprintf is interpreted as readable characters rather than special codes.

The slideshow program cannot be changed, so that isn’t an option. Any direction would be greatly appreciated.



Two possibilities come to mind:

From the comments, that appears to be what was requested. Arrow (cursor) key escape sequences are well-standardized, as shown in

If that works for you, one of the pitfalls is that you probably have to do frequent fflush‘s to make it work.