On 2/28/2022 8:18 PM, jtyler wrote:
>
> In the OP's case, I would suggest a somewhat different approach to
> eliminate the need for an event timer and be more user responsive.
>
Here's an implementation of what I suggested, with button 1. It doesn't
look into the future, only the past. It will trigger a do something on
the first left click, but not on ones that occur quickly after that (for
any number of extra fast clicks). No timers. No delays to wait for
possible double clicking. But a bit more code than I would have hoped.
It also doesn't do the something if the left button was long pressed and
a right click callback can test if the left is still down.
array set ::lmb [list down 0 0 [clock milliseconds] 1 [clock
milliseconds] 2 [clock milliseconds] 3 [clock milliseconds] ]
set ::double_time 300
proc shift {status} {
global lmb
set lmb(3) $lmb(2)
set lmb(2) $lmb(1)
set lmb(1) $lmb(0)
set lmb(0) [clock milliseconds]
set lmb(down) $status
}
proc btime {} { ;# time for button 1 down and up again
expr { $::lmb(0) - $::lmb(2) }
}
proc htime {} { ;# time button 1 was held down
expr { $::lmb(0) - $::lmb(1) }
}
proc press {} {
shift 1
puts "[format %10s [btime] ] press down = $::lmb(down) "
}
proc release {} {
shift 0
# puts "hold time [htime]"
if { [htime] < 500 } {
if { [btime] > $::double_time } {
puts "\ndo it YES ********"
}
} else {
puts "\ndo it NO hold time too long [htime]"
}
puts "[format %10s [btime] ] release down = $::lmb(down) "
}
proc rpress {} {
if { $::lmb(down) } {
puts "right click while left is down"
} else {
puts "right click while left is up"
}
}
package require Tk
catch {console show}
button .path -text "label"
pack .path -fill both -expand true
bind .path <ButtonPress-3> rpress
bind .path <ButtonPress-1> press
bind .path <ButtonRelease-1> release