Difference Between keydown and keypress Events

This page preserves the original comparison between keydown and keypress, but updates the displayed value to event.key rather than the old normalized event.which key number.

Press character keys, arrow keys, Escape, Shift and other controls. The keydown panel should react more consistently. The keypress panel is shown only for legacy comparison.
keydown details appear here
keypress details appear here

jQuery Source Top ↑

$( function () {
    $( document ).on( "keydown", function (event) {
        $( "#d1" ).text(
            "keydown | key: " + event.key + " | code: " + event.code
        );
    });

    $( document ).on( "keypress", function (event) {
        $( "#d2" ).text(
            "keypress | key: " + event.key
        );
    });
});

HTML Top ↑

<div id="d1" class="alert alert-primary">
    keydown details appear here
</div>

<div id="d2" class="alert alert-secondary">
    keypress details appear here
</div>

What to Use in New Code Top ↑

Use keydown when you need to respond to specific keyboard controls. For text changes inside an input or textarea, use the browser input event instead of relying on keypress.

keydown tutorial · keypress legacy reference · modern key identification






plus2net.com






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer