Thanks
--
Googie
Thomas
"Googie" <do...@want.a.spam.org> schrieb im Newsbeitrag
news:bat9u1$56l$1...@atlantis.news.tpi.pl...
bind . <KeyPress-a> "code1..."
bind . <KeyRelease-a> "code2..."
While keeping key pressed first bind invokes my code1, where inside this
code is some 'if' expression which checks if code has been runned before,
if true, then does nothing, else does code1 <- it is protecion from multi
execute code1 while keeping key 'a'. Now, second bind should invoce code2
only when key 'a' has been released, but it also invoces that code while
keeping key 'a' pressed. How to ommit it?
Thanks
--
Googie
Hi Googie,
you're fighting against an auto-repeating keyboard.
The solution is to start a timeout timer on Key-Release
and then start the Key-Release procedure if no Key-Press
arrives within that interval.
Or disable auto repeat of your keyboard.
Best regards
Ulrich
> bind . <KeyPress-a> "code1..."
> bind . <KeyRelease-a> "code2..."
Ulrich had your answer. A specific test is:
set aa {}
bind . <KeyPress-a> {after cancel $aa}
bind . <KeyRelease-a> {set aa [after 1 { puts "release a" }]}
Donald Arseneau as...@triumf.ca
rather use a larger number (than 1) as first argument to after,
because autorepeating keys usually don't fire even nearly as
often as once per millisecond ;-) [after] takes milliseconds!
Here, on my machine, key-repetition is currently set to:
" auto repeat delay: 660 repeat rate: 25
which means, that if (with these settings) you'd use
a number between 25 and 660, you might get one
Press-Release prompt, and a second such pair after
660ms (when the actual repetition starts).
waiting for more than 660ms otoh, will give you
a noticeably delayed release-detection.
If you need "real-time" Press and Release-events, you won't
get around finding os-specific ways to disable auto-repetition.
On unix, eg., this would be
exec xset r on (for turning repetition on)
exec xset r off (for turning repetition off)
It's also possible to do this for specific keys,
but you'd have to know their keycode in advance.
--
Nichts ist schlimmer als zu wissen, wie das Unheil sich entwickelt,
und voll Ohnmacht zusehn muessen - das macht mich voellig krank...
-- (Musical Elisabeth; "Die Schatten werden laenger")
> Donald Arseneau <as...@triumf.ca> wrote:
> > bind . <KeyPress-a> {after cancel $aa}
> > bind . <KeyRelease-a> {set aa [after 1 { puts "release a" }]}
>
> rather use a larger number (than 1) as first argument to after,
> because autorepeating keys usually don't fire even nearly as
> often as once per millisecond ;-)
That delay is not the repetition rate of the autorepeat!
During auto-repeat, you will get pairs of
<KeyRelease-a><KeyPress-a> generated with zero time between
them, and, say, half a second between these pairs.
<KeyPress-a> ...a few seconds... <KeyRelease-a><KeyPress-a> ...660ms...
<KeyRelease-a><KeyPress-a> ...660ms... <KeyRelease-a><KeyPress-a> ...660ms...
Donald Arseneau as...@triumf.ca
*holds hand before one of his eyes and stares at it again*
Indeed !
Sorry for posting first, and actually trying much too late ...