คุณสมบัติ event.ctrlKey
คุณสมบัติ event.ctrlKey ช่วยให้สามารถตรวจสอบได้ว่า
ปุ่ม Ctrl ถูกกดในระหว่างเหตุการณ์หรือไม่
ไวยากรณ์
event.ctrlKey;
ตัวอย่าง
ในตัวอย่างต่อไปนี้ เมื่อคลิกที่ปุ่ม
เราจะแสดงข้อความแจ้งว่าหนึ่งในปุ่ม
Ctrl, Alt หรือ Shift ถูกกดหรือไม่:
<button id="button">click me</button>
let button = document.querySelector('#button');
button.addEventListener('click', function(event) {
if (event.ctrlKey) {
alert('กด Ctrl');
}
if (event.altKey) {
alert('กด Alt');
}
if (event.shiftKey) {
alert('กด Shift');
}
});
:
ดูเพิ่มเติม
-
คุณสมบัติ
event.altKey,
ซึ่งตรวจจับการกดปุ่ม Alt -
คุณสมบัติ
event.shiftKey,
ซึ่งตรวจจับการกดปุ่ม Shift -
คุณสมบัติ
event.metaKey,
ซึ่งตรวจจับการกดปุ่ม Cmd