# keyup 鍵盤事件 - 偵測是否按下特定鍵盤 ## 觸發時機 當你按下特定鍵盤又放開的那刻就會被觸發。 ## 使用方式 HTML: ```htmlembedded= <input type="text"> ``` JavaScript: ```javascript= //透過 querySelector 選取 input 欄位 const input = document.querySelector('input'); //註冊監聽 input 欄位的 "keyup" 事件 input.addEventListener("keyup", function (e) { console.log(e); }); ``` 檢查:`console.log(e)`  可以知道: > 當按下 `r` , `key='r'`,可以利用鍵盤按鍵去執行需要觸發的事件。 >  ## keyup 配合 `.key` 找到特定鍵盤按鍵觸發事件 codepen: <iframe height="300" style="width: 100%;" scrolling="no" title="" src="https://codepen.io/unayo/embed/abwBrOd?default-tab=js%2Cresult&theme-id=dark" frameborder="no" loading="lazy" allowtransparency="true" allowfullscreen="true"> See the Pen <a href="https://codepen.io/unayo/pen/abwBrOd"> </a> by unayo (<a href="https://codepen.io/unayo">@unayo</a>) on <a href="https://codepen.io">CodePen</a>. </iframe> ###### tags: `JS` {%hackmd @unayojanni/H1Qq0uKkK %}
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up