Greetings all,
I've struck a minor problem with perl/Tk's widget bind() procedure, mainly that it doesn't work as documented - as far as I can tell.

I'm using the latest Perl/Tk from CPAN, w/perl 5.6.1, and as well as reading the POD, I've got Advanced Perl Programming and am hovering over the Perl/Tk chapters.

My first task is to bind to keys, which works as so:

$MW->bind('<k>', \&CallbackSub);
However the Advanced Perl Programming documented use of Ev() does not work for me, ala:
$MW->bind('<Any-KeyPress>', [\&mysub, Ev('k')]);
This returns a HASH object, not the key pressed. By doing the following I can get a SCALAR to be returned - but am not sure how to interpret the scalar:
$MW->bind('<Any-KeyPress>', sub { &mysub(Ev('k')) });
The next thing thats eluding me is binding the arrow-keys. (What I was hoping Ev() would tell me was the arrow-key ASCII code that I could use to bind them). I figured I'd be smart and bind 8, 6, 4 and 2 and just let keep the NumLock on - but binding those numbers does NOT bind the numeric keypad number keys!

Who can enlighten me as to whats going on, and how I should go about doing my final object.

JP,
-- Alexander Widdlemouse undid his bellybutton and his bum dropped off --

Edit Masem 2002-02-19 - fixed tags to use CODE instead of font changes


In reply to Keyboard input with Perl/Tk's -bind() by JPaul

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.