คุณสมบัติ event.altKey
คุณสมบัติ event.altKey ช่วยให้ตรวจสอบได้ว่า
ปุ่ม Alt ถูกกดในระหว่างเหตุการณ์หรือไม่
ไวยากรณ์
event.altKey;
ตัวอย่าง
ในตัวอย่างต่อไปนี้ เมื่อคลิกที่ปุ่ม เราจะ
แสดงข้อความว่า มีการกดปุ่มใดปุ่มหนึ่งในบรรดา
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.ctrlKey,
ซึ่งตรวจจับการกดปุ่ม Ctrl -
คุณสมบัติ
event.shiftKey,
ซึ่งตรวจจับการกดปุ่ม Shift -
คุณสมบัติ
event.metaKey,
ซึ่งตรวจจับการกดปุ่ม Cmd