in reply to Capture keypress while process running

This should get you started:

#! perl -slw use strict; use Term::ReadKey; while( 1 ) { my $key = ReadKey 0.1; print 'Got: ' , defined $key ? "'$key'" : ' nothing!'; } __END__ c:\test>"ReadKey(Term).pl" Got: nothing! ... Got: nothing! Got: ' ' Got: nothing! ... Got: nothing! Got: 'v' Got: nothing! Got: nothing! Got: nothing! Got: 'V' Got: nothing! ... Got: nothing! Terminating on signal SIGINT(2)

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP PCW

Replies are listed 'Best First'.
Re^2: Capture keypress while process running
by jcsoybomb (Initiate) on Jul 31, 2009 at 18:18 UTC
    Yes! That is exactly what I wanted, thank you! Now to dissect your code... copying without understanding is cheating.
      On Linux, this code produces: Segmentation fault I do not understand what is happening behind the scenes using ReadKey. But what I can tell is: my $inp = ReadKey 0; works just fine on Linux, and for me, also on Win 7 x64, perl 5.14.4 MSWin32-x86-multi-thread For the records: (v5.16.0) built for x86_64-linux-thread-multi, openSUSE 12.2 (x86_64) Hope to be of help to someone. Bogi