scope puzzle with menus

Charles Hartman charles.hartman at conncoll.edu
Wed Nov 16 07:53:41 EST 2005


On Nov 16, 2005, at 1:39 AM, J. Landman Gay wrote:

> Well, if you open the message watcher and then press and release a  
> key you'll see something like this:
>
> rawKeyDown
> keyDown
> rawKeyUp
> keyUp
>
> Each of those is a different system message and each carries as a  
> parameter the key you have pressed and/or released. If you hold  
> down the Command key while doing the same thing, you only get these  
> messages:
>
> rawKeyDown
> rawKeyUp
> keyUp
>
> There is no "keydown" message sent when the Command key is down.  
> You can take advantage of that to trap only plain keypresses.
>
> Let's say you've pressed Cmd-U. The reason the key is included in  
> your script local when using a "keyUp" handler is because Rev is  
> sending both rawKeyUp-U and keyUp-U. The menus act on the  
> rawKeyDown/Up messages, but that's only half the set; your script  
> is trapping the keyUp and storing the "U".
>
> It is natural to think of a keypress as a single "up" or "down"  
> event, but it's really two sets.

No no, thank you, but I understand that (though I didn't know about  
the command key exception, which is a very handy fact). My question  
isn't about the keypresses or the messages, but about the variable.

Scripture saith: "The difference between a script local variable and  
a global variable is that a script local variable can only be used in  
the handlers of one script . . ." I've always extrapolated that to  
mean that the value of a s.l.v. can be changed only by a handler  
within the script that declares the variable. But in this case it's  
being changed by something from outside the handler, isn't it?

A keyUp message whose parameter is cmd-U is generated when I choose a  
menu item whose purpose is to open a substack. So it's generated  
before I have even opened the substack containing the card containing  
the field whose script contains the keyUp handler. That handler then  
calls a handler in the main stack, which reads and writes a variable  
there in the main stack script. So why does that cmd-U (or the 'u'  
part of it) end up in that variable?

Charles Hartman




More information about the use-livecode mailing list