透過集合功能整理內容
你可以依據偏好儲存及分類內容。
blockly > ShortcutRegistry > addKeyMapping
ShortcutRegistry.addKeyMapping() 方法
在按鍵碼和鍵盤快速鍵之間新增對應項目。
通常只有一個捷徑可對應至任何指定的鍵碼,但如果將 allowCollisions 設為 true,鍵盤就能對應至多個捷徑。在這種情況下,當 onKeyDown 以指定按鍵輸入呼叫時,系統會以相反的順序處理已對應的捷徑 (從最近對應的開始,到最近未對應的結束)。
Signature:
addKeyMapping(keyCode: string | number | KeyCodes, shortcutName: string, allowCollision?: boolean): void;
參數
參數 |
類型 |
說明 |
keyCode |
字串 | 數字 | KeyCodes |
鍵盤快速鍵的按鍵碼。如果要註冊含有輔助鍵的按鍵代碼 (例如 ctrl+c),請使用 ShortcutRegistry.registry.createSerializedKey。 |
shortcutName |
字串 |
按下指定按鍵碼時要執行的快速鍵名稱。 |
allowCollision |
布林值 |
(選用) 如為 true,系統會避免在已對應至捷徑的鍵上新增捷徑時發生錯誤。 |
退貨:
void
例外狀況
如果指定的按鍵代碼已對應至捷徑,則會顯示 {Error}。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-25 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-25 (世界標準時間)。"],[],["The `addKeyMapping` method in `ShortcutRegistry` establishes a link between a key code and a keyboard shortcut name. It takes the `keyCode` (string, number, or `KeyCodes` enum), the `shortcutName` (string), and an optional `opt_allowCollision` (boolean) parameter. It maps a key to a shortcut. If the key is already mapped and `opt_allowCollision` is false, it throws an error. Otherwise no error will be thrown. This method returns void.\n"]]