Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window menu shortcut with non alphanumeric key #2807

Closed
felicienfrancois opened this issue Dec 16, 2014 · 11 comments
Closed

Window menu shortcut with non alphanumeric key #2807

felicienfrancois opened this issue Dec 16, 2014 · 11 comments

Comments

@felicienfrancois
Copy link

The MenuItem.key option accepts only a char.

It would be very useful to be able to map non alphanumeric keys:

  • Arrow keys
  • Page Up / Page Down
  • Function keys (F1 to F12)
  • Home / End
  • Tab, Enter, Backspace, Delete, Escape

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@felicienfrancois
Copy link
Author

By testing it out, I found that part of thoose can be mapped using specific charcode (which don't match javascript keycode):

key = String.fromCharCode(28); // arrow left
key = String.fromCharCode(29); // arrow right
key = String.fromCharCode(30); // arrow up
key = String.fromCharCode(31); // arrow down
key = String.fromCharCode(27); // escape
key = String.fromCharCode(11); // Page up
key = String.fromCharCode(12); // Page down

For some others (like Tab, Backspace), when using the corresponding ascii character, the window menu display well the shortcut (on mac only #2153) but it is not mapped successfully.

And I failed to find a charCode for Function keys (F1 to F12) and Home/End

@tommoor
Copy link

tommoor commented Dec 16, 2014

I believe better documentation is needed here about which keys can be used and the fact that String.fromCharCode is a good alternative.

@felicienfrancois
Copy link
Author

Just added a note to the documentation: https://github.com/rogerwang/node-webkit/wiki/MenuItem#menuitemkey

@tommoor
Copy link

tommoor commented Dec 17, 2014

Great, thanks!

@tommoor tommoor closed this as completed Dec 17, 2014
@felicienfrancois
Copy link
Author

It should not be closed because the String.fromCharCode workaround does not works with all keys.

As I previously said, for example Function keys (F1 to F12) and Home/End cannot be mapped this way.
There is no working solution for its.
Additionaly, the solution is not fully working for Tab, Backspace, Delete and some others.

The issue with thoose keys is that the character code to display the shortcut in the menu is not equals to the keyboard code.
Additionaly, for Function keys, both the character code and the key code is encoded on with bytes.

So the key attribute should be splitted in keyCode and charCode and should accept multiple bytes.
Another more friendly solution is to handle a dictionary (key = "BackSpace", key = "F1", key="Home") and would resolve the keyCode and charCode internally.

@felicienfrancois
Copy link
Author

So this issue should be reopened

@felicienfrancois
Copy link
Author

@tommor or @rogerwang can you please reopen this issue.

I added a note to the documentation with a partial workaround but the issue is not fixed and there is no fully working workaround.

@tommoor tommoor reopened this Jan 3, 2015
@tommor
Copy link

tommor commented Jan 5, 2015

@felicienfrancois just a side note, tommor =/= tommoor, got a notification to an issue i dont take part in ;p. But from what i know in C++ you should use extended ascii codes (IBM PC Keyboard Scan Codes) for function keys that is an array of two rather than one. For expample F1 is (00,59).

@felicienfrancois
Copy link
Author

Sorry @tommor for the mistake.

I tried to use arrays but it does not work. It seems MenuItem.key accepts only a single byte as indicated in the documentation.

Additionally, the main issue here is that this parameter is both used for key mapping AND to display the shortcut in the window menu. It works for alphanumeric character (key mapping code = char code to display) but it does not work for some special characters (like tab, backspace) and for array key codes ((00,59) VS "F1").

Thank you anyway for your help ;-)

@armoret
Copy link

armoret commented Jan 6, 2015

Hi guys,
following the documentation, it seems some key shortcuts are not working as expected.

The following is not working (tested with 0.11.5 win32):

        item = new gui.MenuItem({
            "label": "Forward",
            "click": function() {
                console.log("Forward");
                forward();
            },
            "key": String.fromCharCode(29), // arrow right
            "modifiers": "alt",
        });

and for comparison, this one is working:

        item = new gui.MenuItem({
            "label": "Forward",
            "click": function() {
                console.log("Forward");
                forward();
            },
            "key": "s",
            "modifiers": "alt",
        });

Best regards

@ghostoy
Copy link
Member

ghostoy commented Aug 17, 2016

It should be supported since NW 0.13.0 for Shortcut and MenuItem APIs.

@ghostoy ghostoy closed this as completed Aug 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants