DOM

KeyboardEvent.altKey プロパティ

 編集:2022.10.13 by T.A.

[Edge]○。読取専用。→

イベント発生時に Alt キー(macOS では Option または )が押されたか否かを論理値で示します。

構文
KeyboardEvent.altKey
KeyboardEvent KeyboardEvent

論理値。true:押された。false:押されていない。

keydown イベントで各種表示

HTML:

<SPAN id=IdTest1>[SPAN要素。ここをクリックしてキー操作…]</SPAN><BR>
<SPAN id=IdTest2 contenteditable>[SPAN要素。ここで編集操作…]</SPAN><BR>
<INPUT id=IdTest3 type=text><BR>
<SPAN id=IdLog></SPAN>

JavaScript:

function Job(eve){ //keydown イベントの処理:
  D=eve;
  IdLog.innerHTML="key:"+ eve.key +"<BR>"
	+"code:"+ eve.code +"<BR>"
	+"shiftKey:"+ eve.shiftKey +"<BR>"
	+"ctrlKey:"+ eve.ctrlKey +"<BR>"
	+"altKey:"+ eve.altKey +"<BR>"
	+"metaKey:"+ eve.metaKey;  //表示。
//  eve.preventDefault();
}
IdTest1.onkeydown=Job;  //イベント割り当て。
IdTest2.onkeydown=Job;  //イベント割り当て。
IdTest3.onkeydown=Job;  //イベント割り当て。

編集できない要素ではイベントは発生せず。

Element:keydowninnerHTMLEvent.preventDefault()


テスト