Keyboard Shortcut for a button in adobe air - actionscript-3

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;
}
}

Related

AIR Keyboard shortcut for a button

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)
{
}

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 ;)

Double right click mouse event in AS3?

It it possible to catch a double right click event in Actionscript 3?
It is with AIR. You can't capture RIGHT_CLICK in regular AS3, unfortunately.
There is, however, always the possibility of capturing right click events in JavaScript, and using ExternalInterface to call an event handler in the Flash program. See this blog, for example.
Actually you can catch RIGHT_CLICK at the moment :
You need player >11.2
Add additional compiler options -swf-version=19
Use this code :
stage.doubleClickEnabled = true;
stage.addEventListener(MouseEvent.RIGHT_CLICK, handler);
In handler you can save time of previous click, compare with second click and if it`s shorter than 0.5 seconds dispatch your own RIGHT_DOUBLE_CLICK event.

How to detect if the delete key was pressed in Actionscript 3?

How do I determine if the delete key was pressed using actionscript?
addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
...
function onKeyUp(event:KeyboardEvent):void
{
trace(event.keyCode);
}
The above code yields no value when delete, backspace, enter, and other command keys are pressed. However, arrow keys do yield values.
this.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPressed);
....
function onKeyPressed(event:KeyboardEvent):void
{
if (event.keyCode==Keyboard.DELETE) {
.....
}
}
it's workin nice...
But if you test movie from Flash, it will not work, so export to swf and test....
Just guessing you are using the TEXT_INPUT event, this doesn't work for delete and backspace. To catch those ones you can add an eventListener on the stage and listen to a KeyboardEvent.
Code will work fine if the display object that you attached the listener is in focus. For global listening, as Theo said, you have to attach the listener to the stage. Accessing stage from an object that's not yet added to the display list will result in null error. Do it in the ADDED_TO_STAGE event handler to be safe.
Old thread, but if anyone gets this far: in the Flash Player inside the IDE, these keys are associated with shortcuts. When you test your movie, choose Control>disable keyboard shortcuts in the player and you'll get the events back.