Hey Monks,

I'm kinda stuck getting the special keys (PgUp, PgDn, Left Arrow. F1 etc...) to work in Windows. Even if I follow links found on the internet.
use Term::ReadKey; use Time::HiRes qw( usleep ); use strict; use warnings; ReadMode(4); my $old_ioctl = ioctl(STDIN,0,0) || -1; # Gets device info printf "System returned %d\n", $old_ioctl; $old_ioctl &= 0xff; ioctl(STDIN,1,$old_ioctl | 32); # Writes it back, setting bit 5 $| = 1; while(1){ my $char; while (!defined ($char = ReadKey(-1))){ usleep 1_100; } my $ord = ord($char); last if ($ord == 3); last if ($ord == 4); last if ($ord == 27); if ($ord == 0) { #my $c; #sysread(STDIN,$c,1); #print "C: $c\n"; } print $ord . "\n"; } $| = 0;
According to: http://www.perl.com/doc/manual/html/pod/perlfaq5.html#How_can_I_read_a_single_characte it should be rather correct, but Ive found stuff about some needed ioctl.ph http://www.perl.com/doc/manual/html/pod/perlfunc/ioctl.html aswell... In either case, I'm lost and I was hoping someone could provide me with something that actually works! I don't mind if usage of Win32::API or simulair is used. Running the provided code and pressing a special key gives $ord = 0. So far so good I suppose. But the rest doesn't work. Actually, not even the ioctl hack mentioned first doesn't work. (Returns -1)

So, how to make those special keys work propely (so I know which one I pressed) ?

Thanks,
Ace

In reply to Getting special keys to work with Term::ReadKey in Windows by Ace128

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.