nw.js icon indicating copy to clipboard operation
nw.js copied to clipboard

Regression: CMD + 1-9 shortcuts not working on OSX

Open pd-l2ork opened this issue 1 year ago • 2 comments

Issue Type

Before opening an issue, please search and see if it has already been raised.

  • [x] Bug Report

  • [ ] Feature Request

  • [x] Successfully reproduced against the latest version of NW.js?

Please use our mailing list or Gitter chatroom to ask questions. The issue tracker is only for bugs and feature requests, in English only. Please note that issues without a repro or code snippet are less likely to be resolved.

Current/Missing Behavior

Creating a menu shortcut in any code on a Mac that uses CMD + 1-9 keys shows properly in the menu, but cannot be triggered from 0.59 onward, including the latest version. Last time it did work was 0.28.3. CMD + 0 (zero) works, as does any other key combination (including CMD + SHIFT + 1-9). Below is edited excerpt from the group email (available at https://mail.google.com/mail/u/0/#search/nwjs/FMfcgzGqPpkjwsqVJGbdlxXNkkTjBDfh):

I have a software project that has nw.js OSX menu shortcuts for select options set to CMD+1 through CMD+5. Up until 0.28.3 these shortcuts worked just fine (and still do with the latest code when using 0.28.3). However on newer versions (I tried 0.59, 0.62, and 0.67) this shortcut does not register at all ,but only on OSX (I am using 10.14.6). The same appears to have been reported by other users of my software. Please note the same is impossible to test (AFAICT) because Win+1 (or Ubuntu key + 1) key is intercepted by the OS and triggers an OS action.

Curiously, if I set the shortcut to CMD+Shift+1, it works, but CMD+1 alone does not. So, out of all the number keys only 0 works. CMD + 1-9 do not (same behavior as above). All other keys (letters) work fine with CMD+ (or any other combination of modifiers), on any OS.

This is true for both built-in laptop (MBP) keyboard, and an external (USB) full-size keyboard.

As I mentioned, no code has been changed in the software project and this works fine on 0.28.3, but not on 0.59.1, 0.62.1, or the latest 0.67.1. I have not tested versions between 0.28.3 and 0.59.1, so I am unsure which version introduced this regression.

On Windows and Linux the same project uses Ctrl key and there it all works as it should on all versions of nw.js. I am unable to test the same on Windows and Linux since both have other system things mapped to CMD + 1 and other number keys.

Could this be a regression inside nw.js? Latest Chrome browser allows for CMD+1 through n to be used for switching tabs, so I do not believe this is an OS restriction (and it clearly works ok with earlier versions). OSX by default does not use CMD + 1 for anything (as far as I can tell), so this should not be a key combination reserved for the OS (as is the case with Windows and Linux).

Expected/Proposed Behavior

CMD + 1-9 should trigger the menu item with the associated shortcut.

Additional Info

  • Operating System: Affects only OSX (tried on several different OS versions, so it is not OS-specific).
  • NW.js Version: 0.59.1 and newer has been tested and none of them work. 0.28.3 does work. Did not test versions between 0.28 and 0.59.
  • Repro Link: Just use simple code snippet below instead
  • Code snippet:

package.json


{
  "name": "helloworld",
  "main": "index.html"
}

index.html


<!DOCTYPE html>
<html>
<head>
  <title>Menu</title>
</head>
<body>

<p>Press the CMD+1 and note how on OSX doing so does not activate menu item 1 below. This is a problem only on OSX and affects only CMD + 1-9 options.</p>

<script>
// Load native UI library
var gui = require('nw.gui');

// Create menu
var menu = new gui.Menu({ type: 'menubar' });

// Create sub-menu
var menuItems = new gui.Menu();

menuItems.append(new gui.MenuItem({ label: 'Custom Menu Item 1', key: "1", modifiers: "cmd", click: function() {console.log('1 clicked (cmd+1)');} }));
menuItems.append(new gui.MenuItem({ label: 'Custom Menu Item 2', key: "b", modifiers: "cmd", click: function() {console.log('2 clicked (cmd+b)');} }));
menuItems.append(new gui.MenuItem({ label: 'Custom Menu Item 3', key: "1", modifiers: "cmd+shift", click: function() {console.log('3 clicked (cmd+shift+1)');} }));

// create MacBuiltin
menu.createMacBuiltin('Sample App',{
  hideEdit: true,
    hideWindow: true
});

// Append MenuItem as a Submenu
menu.append(
    new gui.MenuItem({
        label: 'Custom Menu Label',
        submenu: menuItems // menu elements from menuItems object
    })
);

// Append Menu to Window
gui.Window.get().menu = menu;
</script>  
</body>

  • Crash report: No crash and no error generated. Just the shortcut does not work.

Note that this may have some similarity with two stale issues reported earlier #7440 and #7463 but it is not the same.

pd-l2ork avatar Aug 15 '22 18:08 pd-l2ork

@sysrage could you confirm that it's not working?

ayushmanchhabra avatar Aug 24 '22 05:08 ayushmanchhabra

@sysrage could you confirm that it's not working?

I can confirm the example code fails to detect when Command+1 is pressed. It correctly detects Command+Shift+1 and Command+B, but not Command+1.

This appears to have been broken since version 0.42.4.

Works: 0.35.0, 0.40.0, 0.42.0, 0.42.3 Fails: 0.42.4, 0.42.5, 0.43.0, 0.45.0, 0.50.0

sysrage avatar Aug 24 '22 14:08 sysrage

@rogerwang this was apparently resolved in 0.70.1. Possibly earlier...

pd-l2ork avatar Nov 08 '22 03:11 pd-l2ork