Perl FAQ 4.30: How can I detect keyboard input without reading it?

Perl FAQ 4.30

How can I detect keyboard input without reading it?

You should check out the Frequently Asked Questions list in comp.unix.* for things like this: the answer is essentially the same. It's very system dependent. Here's one solution that works on BSD systems:

    sub key_ready {
	local($rin, $nfd);
	vec($rin, fileno(STDIN), 1) = 1;
	return $nfd = select($rin,undef,undef,0);
    }

Under perl5, you should look into getting the ReadKey extension from your regular perl archive.


Other resources at this site: