key.js (818B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 const { KeyCodes } = require("resource://devtools/client/shared/keycodes.js"); 8 9 /** 10 * Helper to check if the provided key matches one of the expected keys. 11 * Keys will be prefixed with DOM_VK_ and should match a key in KeyCodes. 12 * 13 * @param {string} key 14 * the key to check (can be a keyCode). 15 * @param {...string} keys 16 * list of possible keys allowed. 17 * @return {boolean} true if the key matches one of the keys. 18 */ 19 function isKeyIn(key, ...keys) { 20 return keys.some(expectedKey => { 21 return key === KeyCodes["DOM_VK_" + expectedKey]; 22 }); 23 } 24 25 exports.isKeyIn = isKeyIn;