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.
Advertisement
Answer
Two possibilities come to mind:
- The expect program can be used to control terminal applications. Its wiki shows An example wherein Expect controls a pager.
- On the other hand, the question Sending Arrow Keys to Popen claims to lead to something useful. In particular, note the accepted answer, pointing to How to send UP arrow key to popen child, which sends the literal escape sequence for the arrow key via the pipe.
From the comments, that appears to be what was requested. Arrow (cursor) key escape sequences are well-standardized, as shown in
- Bash Prompt HOWTO: Chapter 6. ANSI Escape Sequences: Colours and Cursor Movement
- VT100.net: VT100 User Guide: Chapter 3. Programmer Information, e.g.,
CUF
(cursor forward).
If that works for you, one of the pitfalls is that you probably have to do frequent fflush
‘s to make it work.