On KeyDown Bug

J. Landman Gay jacque at hyperactivesw.com
Sun Mar 26 23:57:10 EST 2006


Robert Sneidar wrote:
> Hi Everyone. This may be a bug, I do not know. Observe the following  
> snippet in the script of the stack:
> 
> on keyDown theKey
>   local theModifier
>   put "" into theModifier
>   switch
>   case the optionKey is down
>     put "Opt " after theModifier
>   case the CommandKey is down
>     put "Cmd " after theModifier
>   case the shiftKey is down
>     put "Shft " after theModifier
>   case the controlKey is down
>     put "Ctrl " after theModifier
>   end switch
>   put char 1 to -1 of theModifier into theModifier
>   replace " " with "-" in theModifier
>   put theModifier && theKey
>   pass keyDown
> end keyDown
> 
> This SHOULD put the modifier keys and the key typed in the result of  
> the message box. It works when I just type letters. BUT when I use a  
> modifier that is NOT the shift key, I get NOTHING. IF I use the Shift  
> key I get "Shft-Crtl " followed by the letter typed, even though the  
> Control key is NOT down!
> 
> Well this cannot be right! What is really needed is a new argument in  
> the keyDown and keyUp handlers for the modifier keys. I should be  able 
> to write the handler this way:
> 
> on keyDown theKey, theModifiers
> if "Shift" is in theModifiers then
>   -- some stuff here
> end if
> pass keyDown
> end keyDown
> 
> I guess this is a bug report AND a feature request.

It's not a bug, it is how keydown works. The keydown message only 
reports, for the most part, typeable keys. In the case of the option 
key, for example, no keypress is generated until you also press another 
key; that is how, on a Mac, you make international characters.

You can use rawKeyDown instead to catch a few of the other keys, such as 
delete, tab, and the arrow keys. See the docs. The rawKeyDown message 
receives the keypress as a number rather than as a character, so you 
need to interpret those. We can help you if you need it.

But some keys are simply never reported by the operating systems during 
normal keyboard input. Modifier keys like shift, command, control, and 
option are not reported, so Rev can't know about them. If you need to 
know the state of some of these keys, you can use the keysdown() 
function, which specifically checks to see if they are depressed.

It is common for new users to think unexpected behaviors are bugs, so 
I'm glad you asked here first. It's always a good idea.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com



More information about the Use-livecode mailing list