Use a ReadMode of 'cbreak', not 'noecho'. The mode you've been using ('noecho') is buffered, which is not what you want. Also, be sure to set the ReadMode to 'restore' prior to terminating, or you'll end up with a wonky terminal! :)

Finally, your $key relational tests need to use eq instead of ==, since it needs to be a stringwise comparison. With these changes it should work for you. ...at least the keyboard input part works. There's also a user-experience issue: The skier has no view of what's ahead, only what is behind or to the side. That would make for a terrible skiing experience! ;)

See below:

use Term::ANSIScreen qw/:color :cursor :screen/; use Term::ReadKey; ReadMode('cbreak'); cls; #fill the screen with Ts $y = 1; while ($y < 100) { $col = int(rand(80)); printf ("%${col}s\n", T); $y = $y + 1; } $wait = .5; $skierx = 40; $skiery = 0; $y = $y + 5; while (1 < 2) { while (not defined ($key = ReadKey(-1))) { # No key pressed $col = int(rand(79)); $y = $y + 1; locate $y,$col; print "T\n"; $skiery = $y - 50; locate $skiery,$skierx; print "V"; #locate $y,1; print "$skiery $skierx $key"; select(undef, undef, undef, $wait); #pauses here $wait = $wait - .003; } # here when key pressed if ($key eq "j") {$skierx = $skierx - 1;} if ($key eq "k") {$skierx = $skierx + 1;} if ($key eq "x") { exit;} } END{ ReadMode('restore'); # Don't leave the terminal wonky. print "\n"; # Don't leave the prompt in a weird place. }

Also, on my Linux system the use of the Win32 related module was not necessary (and of course, not possible). I don't see anything in the script that actually makes use of that module. Are you sure it's necessary? (It may be; I don't do much with Windows these days, so I'm only speculating that it's not.)


Dave


In reply to Re: newbie learning perl by davido
in thread newbie learning perl by mkesling

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.