[w3c/uievents] Proposal: Provide OS specific shortcut key (Issue #412)

ausi created an issue (w3c/uievents#412)

I’d like to propose a way to get the modifier key that is usually used for shortcuts in the users operating system. This would be `Meta` on Apple devices and `Control` on Windows and most Linux devices.

Currently there is no way to retrieve that information and you have to fall back to browser detection, [usually by using `navigator.platform`](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform#determining_the_modifier_key_for_the_users_platform).

If we could have a static property like `UIEvent.SHORTCUT_KEY` that is either set to `"Control"` or `"Meta"` we would have a reliable way to use the correct modifier key for keyboard shortcuts.

***

### Current solutions to this problem:

1.  Many frameworks and applications try to detect the correct key by using code like:
    
    ```js
    navigator.platform.startsWith("Mac") || navigator.platform === "iPhone"
    ```
    
    This is very error prone because there are many different permutations of this platform check and most of them do not consider all cases. For example the code from above lacks an `iPad` and also ignores the fact that the `iPhone` string can have a suffix like in `iPhone Simulator`.

2.  Some try to support both modifier keys using code like this:
    
    ```js
    if (event.ctrlKey || event.metaKey) { … }
    ```
    
    But this causes problems too as it is possible that different keyboard shortcuts exist that differ just by the used modifier key. For example in Firefox on macOS both <kbd>cmd + X</kbd> and <kbd>ctrl + X</kbd> are in use but they do different things. Also, the user facing documentation gets messy as both keys always need to be mentioned.

3.  Another option is to use the same modifier across all platforms. (This only works with <kbd>ctrl</kbd> because <kbd>meta</kbd> gets intercepted by the OS on Windows.) That however feels very unnatural and confusing for users on macOS and it does not work for listening to common OS shortcuts like <kbd>cmd/ctrl + F</kbd> or <kbd>cmd/ctrl + C</kbd>.

I think all of these solutions are suboptimal and in the end cause problems for both users and authors. 

***

Related issues got discussed previously in https://github.com/w3c/uievents/issues/151#issuecomment-1305673156 and https://github.com/w3c/uievents/issues/28

The related concept `KeyboardEvent.getModifierState("Accel")` was removed, but if I understand it correctly the main concern with it was being a *virtual key* that does not fit well with the other non-virtual modifiers, especially in cases involving multiple modifiers.  
I think this proposal does not suffer from the same problems as it keeps the responsibility for the modifier logic with the author, but provides them the necessary information about the platform.  

The many cases in the wild using the `navigator.platform` workaround (it is even suggested to use it for this specific use case on [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform#determining_the_modifier_key_for_the_users_platform)) and the many tickets and discussions that exist around this topic indicate that this is a real problem that authors face regularly.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/uievents/issues/412
You are receiving this because you are subscribed to this thread.

Message ID: <w3c/uievents/issues/412@github.com>

Received on Sunday, 18 January 2026 00:05:37 UTC