zer has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I am trying to test out this module for personal interest.

#!/usr/bin/perl use strict; use warnings; use Term::ReadKey; ReadMode 'cbreak'; #or preferably 'noecho' print "Hit a key: "; my $c = ReadKey 0; print "You typed $c\n"; ReadMode 'restore';

this generates an error of

GetConsoleMode failed, LastError=|6| at C:/Perl/site/lib/Term/ReadKey.pm line 264.

Any insight on this would be good. This is a Windows system.

2006-03-22 Retitled by planetscape, as per Monastery guidelines
Original title: 'Term::Readkey GetCouncilMode error'

Replies are listed 'Best First'.
Re: Term::Readkey GetConsoleMode error
by GrandFather (Saint) on Mar 22, 2006 at 04:26 UTC

    Works as expected for me. What character did you use as your test character? What version of Windows and Perl are you using?

    Nice post BTW - much improved on your previous one. :)


    DWIM is Perl's answer to Gödel
Re: Term::Readkey GetConsoleMode error
by zer (Deacon) on Mar 22, 2006 at 04:30 UTC
    ya thanks granpa ;) Im working on making things pretty now hehe.

    I am using windows XP home. And the program doesnt run at all... it goest straight into the error.
    on debuging the problem is with the "ReadMode". If you comment those out the program goes into an infinit loop of input.
    update:I also upgraded the Term::Readkey and perl is 5.008007.

      ppm.activestate.com - say that TermReadKey ver 2.3 works on windows and that is what i installed.

      and the version of Perl is?

      How did you install Term::ReadKey (if it's not core with your version of Perl)?


      DWIM is Perl's answer to Gödel
Re: Term::Readkey GetConsoleMode error
by w3b (Beadle) on Mar 22, 2006 at 06:46 UTC
    I put the blame on Windows or Perl Version... in Debian 3.1 with perl v5.8.0 it work correctly... In my opinion you have to think about other way to do that:) In perl are many methods to solve a one problem
Re: Term::Readkey GetConsoleMode error
by zer (Deacon) on Mar 22, 2006 at 06:53 UTC
    ya but none of these are working for me... maybe i should just throw windows in the trash...

    i could just write a c program that gets the input and just pipe it...

    that would be bad for system resources

    another thing about *nix, it is easy to do the input esp with stty... but perl is cross compatable for the most part

        InKey works thanks. For some reason Komodo still produces an error... maybe i gotta stop using komodo and just do the command line thing...
        Here is working code. The demo file in the distribution has some more to it.
        #!/usr/bin/perl use strict; use lib qw(.); use Term::InKey; my ($x,$bullet); $|=1; &Clear; print "Hit a key: "; $x = &ReadKey; &Clear; print "You typed $x";

        Komodo 3.52 spits out
        Hit a key:
        Not implemented on MSWin32: The handle is invalid at C:/Perl/lib/Term/InKey.pm line 32.

        again this works in regular dos

Re: Term::Readkey GetConsoleMode error
by zer (Deacon) on Mar 22, 2006 at 05:00 UTC
    i wish there was a more obviouse way to do this. I want to mimic the getchar/getc function from C in perl. There is getc in perl but it doesnt doesnt stop reading after each char. Also it always echo's.

    Even posix doesnt support this because of the perl getc function. *grumble grumble grumble*

      hrrmmm.... in O'Reilly's "Programing Perl" it says, "Avoid getc for anything but single-character terminal I/O. In fact, dont use it for that either. Use sysread."

      #!/usr/bin/perl use warnings; use strict; my $c; my $t = sysread STDIN,$c,1; print "You input $c with $t";

      This still doesnt work... It gets an infinite amount of input and never exits. Am i doing this right?