KeyboardEvent: thuộc tính ctrlKey

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Thuộc tính chỉ đọc KeyboardEvent.ctrlKey trả về một giá trị boolean cho biết phím control có được nhấn (true) hay không (false) khi sự kiện xảy ra.

Giá trị

Một giá trị boolean.

Ví dụ

html
<p>
  Nhấn bất kỳ phím ký tự nào, có hoặc không giữ phím CTRL.<br />
  Bạn cũng có thể sử dụng phím SHIFT cùng với phím CTRL.
</p>
<pre id="output"></pre>
js
const output = document.getElementById("output");

function showChar(e) {
  output.textContent = `Phím KeyDown: "${e.key}"
Phím CTRL KeyDown: ${e.ctrlKey}
`;
}

document.addEventListener("keydown", showChar);

Đặc điểm kỹ thuật

Specification
UI Events
# dom-keyboardevent-ctrlkey

Tương thích trình duyệt

Xem thêm