I'm writing a GUI that will take user input from the keyboard. When the user presses a key it calls a function, and when the key is released it calls another. This seems easy enough to do with Tk's KeyPress and KeyRelease. The problem I'm encountering, and it's probably the stupidest thing ever, is what happens when the key is held down. If the user holds the key down, I want the GUI to wait for the key release before doing anything. Instead, the keyboard/computer automatically starts pressing and releasing the key really fast and stops this when the user actually releases the key. How to I get around this? What I want to do is sort of like a video game. Press and hold left to move left, release to stop. The way it is now, I'll be starting and stopping really fast. Some sample code:
$top->bind('<KeyPress-KP_Left>' => \&left); $top->bind('<KeyRelease-KP_Left>' => \&stop);

In reply to Tk bind KeyPress KeyRelease Problem by Anonymous Monk

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.