Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a little script where I bind a KeyRelease and have some functions perfomred but how would I go about having the functions performed only if the key pressed, say is NOT the CTRL key or the space bar or even enter key?

Here is the psuedo code I have.

$widget->bind('<KeyRelease>', sub {do some stuff;};
what I am wanting is something like the following but am unsure of the syntax.
$t->bind('<KeyRelease>', sub {do some stuff if ((<KeyRelease> != CTRL) + || (<KeyRelease> != Space Bar) || (<KeyRelease> != Enter))});

Replies are listed 'Best First'.
Re: Conditional check on Tk bind?
by mawe (Hermit) on Aug 09, 2004 at 21:38 UTC
    Hi!

    I would do it like this:
    use Tk; my $top = MainWindow->new(); $top->bind("<KeyPress>" => [\&click,Ev('K')]); sub click { my ($window, $button) = @_; if ($button eq 'Control_L') { # ignore left Ctrl print "I don't do anything"; } else { print $button; } } MainLoop();

    Hope this helps.
    mawe
Re: Conditional check on Tk bind?
by japhy (Canon) on Aug 09, 2004 at 20:33 UTC
    You'd need to keep track of what key was pressed. I'm not a Tk user, so I don't know how to go about doing that offhand.
    _____________________________________________________
    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart