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

Hi, I have a number of items on a canvas, and I am trying to set it up so that the item id is sent to a subroutine when the mouse button is held down, and dragged across the items. The problem is the B1 modifer does not work, as it has to actually be pressed, not just held down. here is the code I tried (Enter is the event for when the cursor enters the widget's space on the canvas):
$cnv_reference_ref->bind("location$x", '<B1-Enter>' => [\&click_select +, "$i", "1"]);
I did get this code to work:
$cnv_reference_ref->bind("location$x", '<Control-Enter>' => [\&click_s +elect, "$i", "1"]);
So, that I can 'select' things by holding the ctrl key while dragging the mouse over, but I would really like to be able to just hold the mouse button down. thanks

Replies are listed 'Best First'.
Re: TK binding
by bbfu (Curate) on Apr 08, 2004 at 22:58 UTC

    Have a binding for ButtonPress that sets a flag variable, as well as one for ButtonRelease that clears the flag. Then, have a binding for Motion that returns immediately if the flag is not set, otherwise processes the event normally. Something like:

    my $flag = 0; $cnv_reference_ref->bind("location$x", '<B1-ButtonPress>' => [sub { $f +lag = 1 }, "$i", "1"]); $cnv_reference_ref->bind("location$x", '<B1-ButtonRelease>' => [sub { +$flag = 0 }, "$i", "1"]); $cnv_reference_ref->bind("location$x", '<B1-Motion>' => [sub { return +unless $flag; click_select(@_) }, "$i", "1"]);

    bbfu
    Black flowers blossom
    Fearless on my breath

Re: TK binding
by esskar (Deacon) on Apr 08, 2004 at 20:52 UTC
    try
    $cnv_reference_ref->bind("location$x", '<ButtonPress-1>' => \&click_se +lect, "$i", "1");
    when you release, you have to bind <ButtonRelease-1> to something that stops yozr tracking
      when I use that, it only works for the item that I pressed down on the mouse button for, the other items that I move the cursor over while the button is still down do not activate the subroutine