One idea :
Communication between two independant processes can be done with the help of IPC. In the case of shell script, the simplest is to use FIFOs (names pipe).
So, whenever the viewing application receives keystroke data, it can send the relevant information to the shell script via the FIFO.
At
http://www.linuxjournal.com/content/...pes-fifos-bash, you have an example of a FIFO used for establishing a communication between two shell scripts :
the first one which creates the FIFO and reads whatever is written within (for you : your shell script) ; the second one which writes whatever is useful in the FIFO (for you : your viewing application).