鍵碼·MetaLeft
Meta
MetaLeft
keyCode 91

MetaLeft 鍵碼 — keyCode 91

修飾鍵

MetaLeft 的 keyCode 是 91,key 是 Meta,location 為 1。

單按沒有作用,要壓在別的鍵上。左右共用一個 keyCode。

code(位置)
MetaLeft
key(美式配置)
Meta
keyCode(已廢棄)
91
十六進位
0x5B
location
1 · 左
是否輸入字元
共用 keyCode

在程式裡

用 code 比較,換了鍵盤配置也還能抓住同一個位置。

window.addEventListener('keydown', e => {
  if (e.code === 'MetaLeft') {
    // Meta
  }
});

code 與 key 的區別

code 是鍵盤上的實體位置,韓文鍵盤還是法文鍵盤都一樣。key 是當下敲出來的字元,會變——同一個位置可能是 a、A 或 ㅁ。問「按了哪個位置」用 code,問「輸入了什麼」用 key。

keyCode 已從標準中移除。新程式請用 code 或 key,這裡的數字用來讀舊程式。

同類的鍵

怎麼看這一頁

  • code 是位置,key 是敲出來的字元。做快速鍵要按 code 比較。
  • keyCode 已廢棄,只在讀舊程式時用。
  • 左右 Shift 的 keyCode 相同,靠 location 區分。
  • 數字列的 1 和數字鍵盤的 1 是兩個鍵——49 和 97。

常見問題

Q. MetaLeft 的 keyCode 是多少?

91,十六進位是 0x5B。

Q. 程式裡怎麼判斷 MetaLeft?

用 e.code === 'MetaLeft' 比較。用 keyCode 判斷,會隨瀏覽器和鍵盤配置搖擺。

Q. 這個鍵的 location 是多少?

1。

Q. 按這個鍵會輸入字元嗎?

不會。key 是 Meta,不輸入任何字元。