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