views:

517

answers:

1

I have an AIR app with an <mx:HTML> component, which renders a page that includes an HTML/Javascript-based WYSIWYG/rich-text editor. Various keyboard shortcuts are assigned for formatting and what have you, but if I type a shortcut which isn't assigned (eg. cmd [or ctrl on Win] + M), the character is entered as if no modifier key was pressed. This is even true if the shortcut is assigned but its menu item is disabled.

What is the best way to detect that a modifier is pressed, but the shortcut is not assigned and should be ignored rather than passed through to the HTML view without the modifier key?

+1  A: 

Nevermind, I figured it out. Apparently the menu system operates even if you prevent the default action on the KeyboardEvent:

public var OperatingSystem:String = !!NativeApplication.supportsDockIcon ?
    'mac' :
    !!NativeApplication.supportsSystemTrayIcon ?
    'win' :
    'other';

stage.addEventListener('keyDown', function(e:KeyboardEvent):void {
    if(e[(OperatingSystem == 'mac' ? 'commandKey' : 'ctrlKey')]) {
        e.preventDefault();
    }
});
eyelidlessness