Native Menu Item - function keys as key equivalents

is there any chance to set function keys (eg. F5) as keyEquvalent for NativeMenuItem?



what did you try ? got some sample code?

see Announcement: If you ask for help about code

where are you trying to do that ? AIR Desktop? Windows? macOS? both?

show some sample code and explain what do you expect and what is happening instead
eg. “I try to do that but this instead happen or nothing happen”


Sorry for my “long story short” approach, I thought it will be clear enough :slight_smile:
I’m making an editor app for Windows and decided to use NativeMenu so users can have all editor options visible with associated keyboard shortcuts. Here’s the sample code:

var fileMenu:NativeMenu = new NativeMenu(); 
fileMenu.addEventListener(Event.SELECT, selectCommandMenu); 
var openCommand:NativeMenuItem = fileMenu.addItem(new NativeMenuItem("Open")); 
openCommand.addEventListener(Event.SELECT, selectCommand); 
openCommand.keyEquivalent = "o";
openCommand.keyEquivalentModifiers = [Keyboard.CONTROL];

In this particular example keyboard shortcut for selecting openCommand NativeMenuItem is Ctrl+O.

So, the thing I’m trying to accomplish is to set function key F5 as keyboard shortcut for selecting openCommand NativeMenuItem. Since keyEquivalent property is String class I don’t know what String to enter for F5. If I set it as:

openCommand.keyEquivalent = "f5";

selection event triggers when I press “f”.
So the question is how to set function key F5 as keyboard shortcut and is it possible?


humm I would assume

keyEquivalent only take the first char of the String
so yeah with f5 it would take only f

so as first test I would try based on Keyboard class ref

that if F-keys are supported then you would assign it like that

openCommand.keyEquivalent = String.fromCharCode( Keyboard.F5 );
//openCommand.keyEquivalent = Keyboard.KEYNAME_F5;
//openCommand.keyEquivalent = Keyboard.STRING_F5;
openCommand.keyEquivalentModifiers = [];

if that doesn’t work, then on second try I would do this

openCommand.keyEquivalent = "f5";
//openCommand.keyEquivalent = "F5";
openCommand.keyEquivalentModifiers = [Keyboard.ALTERNATE];

I was thinking same way and already tried all keyEquevalentModifers combinations (CONTROL, ALTERNATE and SHIFT) and it takes only first letter in String “f” if keyEquivalent is set to “f5”.

Also tried Keyboard class but the thing is that Keyboard.F5 returns uint 116 so String.fromCharCode method converts it to letter “t” as in ASCII table so nativeMenuItem is triggered by letter “t”.

It would be much better if keyEquevalent property would accept uint value.

OK …

for the record when someone ask you what you already tried, and later on you answer back with a “oh I already tried all that” (but you did not mention it before did you???) just shows how much you don’t care

it doesn’t really entice to spend time to help you
so good luck