Control
ControlRight
keyCode 17
ControlRight 鍵碼 — keyCode 17
修飾鍵
ControlRight 的 keyCode 是 17,key 是 Control,location 為 2。它和 ControlLeft 共用這個號。
單按沒有作用,要壓在別的鍵上。左右共用一個 keyCode。
- code(位置)
- ControlRight
- key(美式配置)
- Control
- keyCode(已廢棄)
- 17
- 十六進位
- 0x11
- location
- 2 · 右
- 是否輸入字元
- 否
- 共用 keyCode
- ControlLeft
在程式裡
用 code 比較,換了鍵盤配置也還能抓住同一個位置。
window.addEventListener('keydown', e => {
if (e.code === 'ControlRight') {
// Control
}
});code 與 key 的區別
code 是鍵盤上的實體位置,韓文鍵盤還是法文鍵盤都一樣。key 是當下敲出來的字元,會變——同一個位置可能是 a、A 或 ㅁ。問「按了哪個位置」用 code,問「輸入了什麼」用 key。
keyCode 已從標準中移除。新程式請用 code 或 key,這裡的數字用來讀舊程式。
同類的鍵
怎麼看這一頁
- code 是位置,key 是敲出來的字元。做快速鍵要按 code 比較。
- keyCode 已廢棄,只在讀舊程式時用。
- 左右 Shift 的 keyCode 相同,靠 location 區分。
- 數字列的 1 和數字鍵盤的 1 是兩個鍵——49 和 97。
常見問題
Q. ControlRight 的 keyCode 是多少?
17,十六進位是 0x11。
Q. 程式裡怎麼判斷 ControlRight?
用 e.code === 'ControlRight' 比較。用 keyCode 判斷,會隨瀏覽器和鍵盤配置搖擺。
Q. 這個鍵的 location 是多少?
2。它和 ControlLeft 共用 keyCode,要區分就得靠這個值。
Q. 按這個鍵會輸入字元嗎?
不會。key 是 Control,不輸入任何字元。