Differences between keydown and keypress

Source: Internet
Author: User

Although literally speaking, keydown means to press a key, the fundamental difference between the two is that the system uses keydo
Wn returns the code of the keyboard, which is then translated by the translatemessage function into a character, and the value of the character is returned by keypress.
Therefore, in keydown, the keyboard code is returned, while in keypress, the ASCII characters are returned.
If you only want to read characters, use keypress. If you want to read the status of each key, use keydown.
It is wrong to say that keydown is press, keypress is press and release. What if you keep pressing the key? At this moment, real estate continues
Generate keydown and keypress.


Onkeypress can only be triggered when a single key is pressed, and for shift, ALT, Ctrl, and
Assembly. For example, CTRL + F1 does not trigger this message. The message it processes may be wm_char.
Onkeydowm can capture all these buttons.
It actually processes the wm_keydown message.
It can be understood that onkeydown is the superset of onkeypress.

One difference is that keypress is a reaction to simple characters.
Does not respond to shift, F1 functional buttons
Keydown can all be reflected.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.