AIR Keyboard shortcut for a button - actionscript-3

I work with AIR application.
In this application, several windows are displayed.
I like to close windows with shortcuts like Esc and Enter.
I try to do that like this:
// On creation complete
this.addEventListener(KeyboardEvent.KEY_DOWN, exit_keyDownHandler);
// exit function
protected function exit_keyDownHandler(event:KeyboardEvent):void{
if ((event.keyCode == Keyboard.ENTER)
||(event.keyCode == Keyboard.NUMPAD_ENTER)
||(event.keyCode == Keyboard.ESCAPE)){
stage.nativeWindow.close();
}
}
But if a text area exists on window, a problem occured. Because when user presses Enter key text area window closes. How can that be avoided?

Closing with a single key other than the escape key doesn't seem like a very good idea to me, especially not with the enter key.
However, if you insist doing it like that, then you could try checking the current focused object to make sure it's not an input element/component that accepts the enter key.
See FocusManager.getFocus() and Stage.focus. A very restrictive check could for example look like this:
if(focusManager.getFocus() is IFocusManagerComponent ||
stage.focus is InteractiveObject || stage.focus is IFocusManagerComponent)
{
}

Related

WP8 : IExplorer 10 : on "keyup" event not firing for "RETURN" key

I've just came across this interesting problem, or probably it's just me missing something very basic (hopefully). The problem is, that the keyup event is not firing for the return key in the WP8 browser, whereas all the other standard keys are firing this event up.
I've tested this on the desktop, and IE10 is not having any issues with this, the event fires up nicely.
Can anyone else confirm that on their WP8 devices the keyup event is not being triggered for the "return" key ?
/using dojo syntax here/
on(dom.byId("testinput1"), "keyup", function(evt){
dom.byId("result1").innerHTML = "";
if (evt.keyCode == keys.ENTER)
dom.byId("result1").innerHTML = "ENTER pressed.";
});
Here is the jsfiddle link
open it in IE10 -> no problem for both of the input boxes
open it in WP8 browser (IE10) -> the first input box wont trigger keyup for the return key
Thanks for all your help.

Keyboard Shortcut for a button in adobe air

I want to implement keyboard shortcuts for buttons in my Adobe Air application.
I have four buttons in a screen. I want to assign F9, F10, F11, F12 keys to them. How to achieve that? I searched a lot but have not found yet.
Please advice me.
You need to capture key code for F9, F10, F11, F12. For quick, you can get keycode from this site.
http://livedocs.adobe.com/flex/3/html/help.html?content=events_11.html
I saved my all key codes in a constant file. i check pressed button value is equal ko keycode. and dispatched my custom event.
See this page in the LiveDocs. You want to look at the constants.
So you would listen for KeyboardEvent.KEY_DOWN and do something like this:
function keyDownHandler( e:KeyboardEvent ):void {
switch( e.charCode ) {
case Keyboard.F9:
// do something
break;
case Keyboard.F10:
// do something
break;
case Keyboard.F11:
// do something
break;
}
}

Detecting KeyBoard events inside NumericStepper

I have a movie clip with 2 buttons (Ok and Cancel) and one Numeric Stepper.
If the user press enter key on the keyboard I want that "Ok" button function runs and if "BackSpace" is pressed "Cancel" function.
I have this code that detect when I press almost all the keys but not when I press "ENTER" or "BACKSPACE".
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyPressed);
function onKeyPressed(event:KeyboardEvent):void
{
if (event.keyCode==Keyboard.ENTER) {
okBtnFunction();
}
if (event.keyCode==Keyboard.DELETE) {
cancelBtnFunction();
}
}
I also tried with event.charCode.
Enter and Backspace keys aren't enable because of the flash shortcut, you can see it in this link:
Flash AS3: ENTER does not get detected, but CTRL+ENTER works fine
If you try to get keyboard event inside NumericStepper you have to use:
Object(this).YOU_NUMERIC_STEPPER.textField.addEventListener(KeyboardEvent.KEY_DOWN, keyboard_handler);
Remember to use textField after numeric stepper name.

Is it Possible to invoke keyboard Function keys using Chrome Extensions

I am working on Chrome Extensions. I want to know that is it Possible to invoke keyboard Function keys using Chrome Extensions.
Thanks,
NVN.
EDIT: Do you want to simulate function key presses on a page or listen for physical key presses from the user? If you want want to procedurally trigger function key actions, you can't. As Rob pointed out, scripted events only activate scripted event listeners, and do not trigger default behavior.
In order to detect function key presses, you need to bind your events to keyup -- not to keypress, which doesn't fire for several non-printable keystrokes, like function keys and arrow keys.
document.documentElement.addEventListener("keyup", function(e) {
if(e.keyCode == 113) {
// if F2 is pressed...
// F1 is keycode 112, and it increments from there
}
});
Some function keys do things already (F1 opens help, F5 refreshes, etc.). If you have a good reason for preventing this behavior (e.g. you're making an immersive full-screen app like a VNC viewer that shouldn't exhibit normal browser behavior), you can use preventDefault on keydown to stop that potentially disruptive action:
document.documentElement.addEventListener("keydown", function(e) {
if(e.keyCode == 112) {
// if F1 is pressed, don't open help
e.preventDefault();
}
});
To see how to handle key presses for your Chrome extension, see my answer on Activate extension via short cut key; that should be exactly what you need for the rest. Briefly:
the code I gave above goes in a content script that gets added to each page
the event handlers functions perform some action, either within the content script on the page or by passing a message to the background page

how do I enable double click in action script?

I tried to do this :
panel.addEventListener(MouseEvent.DOUBLE_CLICK,showEditPopup);
but it is not working.
It works fine for
panel.addEventListener(MouseEvent.CLICK,showEditPopup);
So, I guess I have to enable double click first. Need help on it.
You have to enable double click for your panel before by doing this :
panel.doubleClickEnabled=true;
And then you can do :
panel.addEventListener(MouseEvent.DOUBLE_CLICK,showEditPopup);
I had this problem this morning trying to add a double click to my game.
This is what i found out.
First of all you gotta enable doubleclick like this:
panel.addEventListener(MouseEvent.DOUBLE_CLICK,showEditPopup);
You can also add the singe CLICK on the same function to prevent click to happen twice when double clicking, like this:
panel.addEventListener(MouseEvent.CLICK,showEditPopup);
Then this would be the function, interacting with both but 1 at a time:
function showEditPopup(e:MouseEvent) {
if (e.type == "click") {
//single click
} else if (e.type == "doubleClick") {
//double click
}
}
Now there is 2 problem that come up. First you gotta enable double click like this before the listener:
panel.enableDoubleClick = true;
Then the worse, if the display object is binded to another display object, which have a mouse event, you have to disable those event for the children so the double click work. Like this:
panel.mouseChildren = false;
That was bad for me because this is what i was doing.
Created a card with skills, skills had mouseevent.move_over to show a tooltip. But then i wanted to double click the card to place it/remove it from the deck. But it was not working because the skills, attached to that movieclip, had mouseevent in them. So i had to disable them and find another way to do it. Because tooltip wasnt showing with that mousechildren set to false and i had no choice to have this to bypass those event.
And this is why the timer solution seem a better idea indeed.You can go as up as 1 second for the wait time of a double click. It won't affect people and will fit even the slowest dude ;)