MouseEvent: ctrlKey 屬性
MouseEvent.ctrlKey 只讀屬性是一個布林值,表示在給定滑鼠事件發生時,Ctrl 鍵是否被按下。
在 Macintosh 鍵盤上,此鍵標有 Control 鍵。另外請注意,在 Mac 上,按住 Control 鍵的單擊操作會被作業系統攔截並用於開啟上下文選單,因此在單擊事件中無法檢測到 ctrlKey。
使用觸控板進行捏合縮放也會發送一個模擬的 wheel 事件,並將 ctrlKey 設定為 true。
值
一個布林值,其中 true 表示按下了該鍵,false 表示該鍵未按下。
示例
此示例在觸發 mousemove 事件時記錄 ctrlKey 屬性。
HTML
html
<p id="log">The ctrl key was pressed while the cursor was moving: false</p>
JavaScript
js
const log = document.querySelector("#log");
window.addEventListener("mousemove", logKey);
function logKey(e) {
log.textContent = `The ctrl key was pressed while the cursor was moving: ${e.ctrlKey}`;
}
結果
規範
| 規範 |
|---|
| UI 事件 # dom-mouseevent-ctrlkey |
瀏覽器相容性
載入中…