Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > bind only "normal" keys in Tk

Reply
Thread Tools

bind only "normal" keys in Tk

 
 
Larry
Guest
Posts: n/a
 
      12-21-2005
In my Tk application, I would like to a routine to be called whenever a
"normal" key is pressed in a certain Text control. By "normal", I mean
a regular ASCII key, not an Alt or Shift key by itself. However, I
can't figure out how to do that directly. The only thing I've figured
out so far is (with no thanks to the Tk documentation, by the way):

$txt->bind('<KeyPress>', \&doKey);

sub doKey {
my $c = shift;
my $k = $c->XEvent->K;

# code which looks at $k to see if it's "normal"
}

This works but it does not seem very efficient. I would like a way
that "doKey" would not get called at all for Alt and Shift keys.

 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      12-21-2005
Larry <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> In my Tk application, I would like to a routine to be called whenever a
> "normal" key is pressed in a certain Text control. By "normal", I mean
> a regular ASCII key, not an Alt or Shift key by itself. However, I


ASCII vs. non-ASCII is the wrong distinction here. A "normal" key
would be one that delivers a character (no matter which code), as opposed
to the modifier keys Alt, Shift, etc. that don't.

> can't figure out how to do that directly. The only thing I've figured
> out so far is (with no thanks to the Tk documentation, by the way):
>
> $txt->bind('<KeyPress>', \&doKey);
>
> sub doKey {
> my $c = shift;
> my $k = $c->XEvent->K;
>
> # code which looks at $k to see if it's "normal"
> }
>
> This works but it does not seem very efficient. I would like a way
> that "doKey" would not get called at all for Alt and Shift keys.


Have you read all the documentation for ->bind? You can restrict key
bindings to any key you want. Just bind all the keys you want a binding
for and leave others alone. To bind all alphanumeric keys (untested):

$txt->bind( "<KeyPress-$_>", sub { print "it happened\n" }) for
'A' .. 'Z', 'a' .. 'z', 0 .. 9;

Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
confused by boost::bind & boost::lambda::bind XHengDF@gmail.com C++ 0 05-29-2007 04:37 AM
How to link foreign keys & primary keys using python? Harry George Python 9 06-13-2006 06:29 AM
Using a data-bind dropdownlist to populate another data-bind dropdownlist mr2_93 ASP .Net 1 10-02-2005 05:07 PM
serial keys/validation keys sandeep Kanwal C++ 1 10-29-2004 06:36 PM
keyboard keys replacing mouse keys? larry Computer Support 8 09-14-2003 07:32 PM



Advertisments