Wednesday, April 18, 2001

Windowing conundrum

Today I was working on a project that requires both the stage and a MIAW to respond to keys being pressed by the user. I don't control the code to the MIAW; it is being provided from another source. I have been attempting to find a way to manage keypress events so that the stage can respond appropriately to them, even if the MIAW is unaware of the context it is being run under.



Unfortunately, there appears to be absolutely no reliable way to give a window or the stage keyboard focus, nor is there any way to determine what window currently has the keyboard focus. About all you can do is trick the user into clicking in the window you want to have keyboard focus.



The only simple way to be sure that one window or another has keyboard focus is to ask each window what its keyboardFocusSprite value is. If an editable text member or a field happens to be being edited in one of the movies, it will return a value other than -1. However, there are many contexts in which you need to accept keystrokes outside of an editable field (such as controlling a character in a game with the arrow keys, or accepting keyboard shortcuts for an editor).



Another (riskier) approach would be to have the stage interfere with the workings of the MIAW by monkeying with its keydownScript and keyUpScript. If the MIAW's do not define these values, then it should not cause a problem. Simply issue a 'pass' in the script to allow normal operation. However, if the MIAW itself needs to define these scripts, then you are in danger of either breaking the MIAW's operation or losing events.



Clearly, the stage has a unique position in relation to MIAW's. It is considered the 'main' movie, the 'controller' movie, from which all MIAW's are spawned and manipulated. But if it is to act as a puppeteer, then it needs to have strings into those puppets. It should be able to insert a hook to get first crack at any input events. Unfortunately, there is no way to do this, and we have to rely on MIAW's to play nice and send important messages down to the stage. When you don't control the code for the MIAW's, this is difficult at best.