// Copyright (C) 2023 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // This module provides hotkey detection using type-safe human-readable strings. // // The basic premise is this: Let's say you have a KeyboardEvent |event|, and // you wanted to check whether it contains the hotkey 'Ctrl+O', you can execute // the following function: // // checkHotkey('Shift+O', event); // // ...which will evaluate to true if 'Shift+O' is discovered in the event. // // This will only trigger when O is pressed while the Shift key is held, not O // on it's own, and not if other modifiers such as Alt or Ctrl were also held. // // Modifiers include 'Shift', 'Ctrl', 'Alt', and 'Mod': // - 'Shift' and 'Ctrl' are fairly self explanatory. // - 'Alt' is 'option' on Macs. // - 'Mod' is a special modifier which means 'Ctrl' on PC and 'Cmd' on Mac. // Modifiers may be combined in various ways - check the |Modifier| type. // // By default hotkeys will not register when the event target is inside an // editable element, such as