++ Works great, I could have used this on some past projects. It's surprising the doubleclick bug has never been fixed. Here's my rough cut at a module version of your code, called in more of a Perl Tk style.

package Tk::Doubleclick; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(bindClicks); sub bindClicks { my %arg = @_; my $btn = delete $arg{-widget}; my $delay = delete $arg{-delay} || 300; my $args1 = delete $arg{-single}; my $args2 = delete $arg{-double}; my $clicked = delete $arg{-button} || 'left'; my %btnTable = ( left => 1, center => 2, right => 3 ); my $mousenum = $btnTable{$clicked} || $clicked; $mousenum = 1 unless ($mousenum =~ /^[123]$/); my $single = $args1; if (ref $args1 eq 'ARRAY'){ $single = shift @$args1; }else{ $args1 = []; } my $double = $args2; if (ref $args2 eq 'ARRAY'){ $double = shift @$args2; }else{ $args2 = []; } my $nclicks = 0; my $c_cmd = sub { ++$nclicks; $btn->after($delay => sub { my $count = $nclicks; $nclicks = 0; if ($count > 1) { $double->(@$args2); } elsif ($count == 1) { $single->(@$args1); } }); }; my $button_name = "<Button-$mousenum>"; $btn->bind($button_name => $c_cmd); } 1; =head1 NAME Tk::Doubleclick - Correct handling of single vs double click callback +bindings =head1 SYNOPSIS use Tk::Doubleclick; bindClicks( -delay => 500, -widget => $button_widget, -button => 'left', -single => [ \&callback, @args ], # with arguments -double => \&callback, # without arguments ); =head1 OPTIONS =over 5 =item -delay Maximum delay time detween clicks in milliseconds. Default = 300. =item -widget Widget to bind to mousebuttons. =item -button Mouse button to bind. Options are left, center, right, 1, 2, 3. Defaul +t = left. =item -single Single click callback. To include arguments, use array reference. =item -double Double click callback. To include arguments, use array reference. =back =cut

Update: fixed typo


In reply to Re: Detect perl/Tk Button double-clicks vs. single-clicks by hangon
in thread Detect perl/Tk Button double-clicks vs. single-clicks by liverpole

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.