--- title: GlobalEventHandlers.onkeydown slug: Web/API/GlobalEventHandlers/onkeydown tags: - API - HTML DOM - NeedsContent - NeedsExample translation_of: Web/API/GlobalEventHandlers/onkeydown ---
{{ApiRef("HTML DOM")}}

onkeydown 속성은 현재 요소(element)의 onKeyDown 이벤트 핸들러 코드를 돌려줍니다

element.onkeydown = event handling code

Example

This example logs the {{domxref("KeyboardEvent.code")}} value whenever you press down a key inside the {{HtmlElement("input")}} element.

HTML

<input>
<p id="log"></p>

JavaScript

const input = document.querySelector('input');
const log = document.getElementById('log');

input.onkeydown = logKey;

function logKey(e) {
  log.textContent += ` ${e.code}`;
}

Result

{{EmbedLiveSample("Example")}}

명세

명세 상태 비고
{{SpecName('HTML WHATWG','webappapis.html#handler-onkeydown','onkeydown')}} {{Spec2('HTML WHATWG')}}  

브라우저 호환성

{{Compat("api.GlobalEventHandlers.onkeydown")}}