I actually just figured out a good answer to this problem. Apparently, the reason cmd-H and cmd-W don't trigger keyDown events are because they are capturee and stopped by the native application menu.
By default, several "normal" mac OS menu options are put into AIR applications by the framework - these include cmd-w to close the window, cmd-h to hide and shortcuts around copy/cut/paste. In order to avoid the default behavior, I either removed these menu options or changed their key equivalents (the shortcut combination that triggers them).
The code to add a preferences shortcut (cmd-,), override cmd-w, change cmd-w to cmd-shift-w, and override the cmd-h functionality looks like this:
if (NativeApplication.supportsMenu) {
var prefItem:NativeMenuItem = new NativeMenuItem("Preferences...");
prefItem.addEventListener(Event.SELECT, handlePreferencesMenuSelect);
prefItem.keyEquivalent = ",";
var closeItem:NativeMenuItem = new NativeMenuItem("Close Tab");
closeItem.addEventListener(Event.SELECT, handleCloseTabMenuSelect);
closeItem.keyEquivalent = "w";
// Add the preferences option under the first menu
// Also add a spacer line (like most other applications)
// Also change the hide command to our own handler
var baseMenu:NativeMenuItem = NativeMenuItem(NativeApplication.nativeApplication.menu.items[0]);
baseMenu.submenu.addItemAt(new NativeMenuItem("", true), 1);
baseMenu.submenu.addItemAt(prefItem, 2);
for (var idx:String in baseMenu.submenu.items) {
var menuItem:NativeMenuItem = baseMenu.submenu.items[idx];
if (menuItem && menuItem.keyEquivalent == 'h' && menuItem.keyEquivalentModifiers.length == 1) {
baseMenu.submenu.removeItemAt(int(idx));
var hideItem:NativeMenuItem = new NativeMenuItem("Hide Application");
hideItem.addEventListener(Event.SELECT, handleHideWindowSelect);
hideItem.keyEquivalent = "h";
baseMenu.submenu.addItemAt(hideItem, int(idx));
}
}
// Set the close window shortcut to cmd+shift+w, instead of cmd+w
var fileMenu:NativeMenuItem = NativeMenuItem(NativeApplication.nativeApplication.menu.items[1]);
NativeMenuItem(fileMenu.submenu.getItemAt(0)).keyEquivalent = 'W';
fileMenu.submenu.addItem(closeItem);
}
Thanks for the help figuring it out.