Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

bind <KeyPress> <KeyRelease>

69 views
Skip to first unread message

Googie

unread,
May 26, 2003, 10:59:33 AM5/26/03
to
Hi
What is a difference betwean above two events? and which event use to bind
key pop (I don't know exactly word for it in english, but I mean - not
push).

Thanks
--
Googie

Thomas

unread,
May 26, 2003, 11:35:48 AM5/26/03
to
I think KeyPress is when you press the key and KeyRelease is when you
release it (in german - loslassen). So at the first one the script starts
before you release the key and at the second one starts after releasing the
key.

Thomas

"Googie" <do...@want.a.spam.org> schrieb im Newsbeitrag
news:bat9u1$56l$1...@atlantis.news.tpi.pl...

Googie

unread,
May 26, 2003, 12:57:54 PM5/26/03
to
Ok. Now I can see it. Well, I have another problem now - <KeyRelease> runs
its script also when I keep binded key pushed and it shouldn't :( I need to
bind under 1 button (let it be 'a') 2 events, something like:

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

Ulrich Schöbel

unread,
May 26, 2003, 7:23:27 PM5/26/03
to

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

Donald Arseneau

unread,
May 27, 2003, 11:57:46 PM5/27/03
to
Googie <do...@want.a.spam.org> writes:

> 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

Andreas Leitgeb

unread,
May 28, 2003, 7:33:08 AM5/28/03
to
Donald Arseneau <as...@triumf.ca> wrote:
> Googie <do...@want.a.spam.org> writes:
>> 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" }]}

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

unread,
May 28, 2003, 12:05:26 PM5/28/03
to
Andreas Leitgeb <Andreas...@siemens.at> writes:

> 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

Andreas Leitgeb

unread,
Jun 2, 2003, 1:31:23 PM6/2/03
to
Donald Arseneau <as...@triumf.ca> wrote:
>> > bind . <KeyPress-a> {after cancel $aa}
>> > bind . <KeyRelease-a> {set aa [after 1 { puts "release a" }]}
>> [my own rubbish snipped]

> 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.

*holds hand before one of his eyes and stares at it again*
Indeed !

Sorry for posting first, and actually trying much too late ...

0 new messages