Определить нажатие комбинации клавиш

В данном вопросе есть ответ (усложненная версия) приложен такой код:

document.addEventListener("keydown", handlerKeydown);
// ...
function handlerKeydown(event)
{
    if (event.code === "KeyF" && (event.ctrlKey || event.metaKey))
    {
        event.preventDefault();
        controlInputText.focus();
    }
}

Так вот, я так понимаю суть была отловить нажатие Ctrl+F. Но оно не срабатывает в Spotify, то есть если я держу Ctrl и нажимаю F, событие не видит этого. Я получаю лишь такой event:

KeyboardEvent {isTrusted: true, key: "Control", code: "ControlLeft", location: 1, ctrlKey: true, …}
altKey: false
bubbles: true
cancelBubble: false
cancelable: true
charCode: 0
code: "ControlLeft"
composed: true
ctrlKey: true
currentTarget: null
defaultPrevented: false
detail: 0
eventPhase: 0
isComposing: false
isTrusted: true
key: "Control"
keyCode: 17
location: 1
metaKey: false
path: (4) [body, html.no-focus-outline.spotify__os--is-windows.spotify__container--is-desktop.buddyfeed-visible, document, Window]
repeat: false
returnValue: true
shiftKey: false
sourceCapabilities: InputDeviceCapabilities {firesTouchEvents: false}
srcElement: body
target: body
timeStamp: 147413.99999998976
type: "keydown"
view: Window {window: Window, self: Window, document: document, name: "", location: Location, …}
which: 17
__proto__: KeyboardEvent

Из чего видим, что не ловится нажатие клавиши F. Что сделано не так?


Ответы (1 шт):

Автор решения: Igor

document.addEventListener("keydown", handlerKeydown);
// ...
function handlerKeydown(event) {
  if (event.code === "KeyF" && (event.ctrlKey || event.metaKey)) {
    event.preventDefault();
    console.log(event.code, event.ctrlKey, event.metaKey);
  }
}

document.querySelector('input').focus();
<input />

→ Ссылка