Just to check we’re chasing the same problem. As I understand it, xfratboy was finding that, if a key is held down, it repeats, and this was causing problems for his implementation. Normally when people type they tap the keys briefly, so a single keyDown/keyUp pair is generated. When pressed and held long enough, multiple keyDown/keyUps are generated. I’m testing under Windows XP, and there are systems settings under Settings:Keyboard Properties: Repeat delay, Repeat rate, which set how long the key must be pressed before it starts to repeat (repeat delay) and how quickly it repeats thereafter (repeat rate). Note these are distinct from the Rev properties repeatDelay and repeatRate, which govern the way scrollbars behave. On a Mac the keyUp is sent immediately after any keyDown handlers are completed (regardless of whether the key is actually released), whereas under Unix and Windows the key must actually be released. I’m not sure this affects the current problem of blocking key repeats, which while normal behaviour, is a problem in some cases. It’s natural for a user to hold down a key until they see it have the desired effect. When typing, this virtually instant. If the keypress is resizing an object and redrawing it on the screen, users can tend to hold the keys down long enough for them to repeat, generating unwanted messages. In this case, checking that the keysDown returns empty ensures that only the last keyUp, after the key is actually released, is registered by the handler.
The problem with special keys like the arrow keys falsely triggering the handler is interesting- the documentation says that these keys don’t generate a keyUp message, but indeed they seem to. The problem is avoided by using rawKeyUp instead, thus:
Code: Select all
on rawKeyUp theKey
if the keysDown is empty then
if theKey is 107 then
beep 1
end if
end if
end rawKeyUp
... for the “k” key test, “i” being 105 and “d” being 100. It’s as if special keys generate keyUps, with theKey equivalent to “any” key. I could have missed the point of the original question, but we've definitely uncovered an oddity about keyUp.
Regards,
Michael