There is a difference between onkeypress and onkeydown. The differences between onkeypress and onkeydown are described below.
The onkeypress event occurs when the user presses and releases any alphanumeric key. However, system buttons (such as arrow keys and function keys) cannot be identified.
The onkeydown event occurs when you press any keyboard key (including system buttons.
Differences:
1. The onkeydown takes place before onkeypress.
2. onkeypress does not support system buttons.
2. the keyCode captured by onkeydown is not distinguished by letter size, but by onkeypress.
Onkeypress occurs when the user presses and releases any alphanumeric key. System buttons (for example, arrow keys and function keys) cannot be identified.
Onkeyup occurs when the user releases any previously pressed keyboard keys.
Onkeydown occurs when you press any keyboard key (including system buttons, such as the Arrow keys and function keys.
Onkeypress
As of Microsoft Internet Explorer 4.0, the onkeypress event fires and can be canceled for the following keys:
Letters: A-Z (uppercase and lowercase)
Numerals: 0-9
Symbols :! @ # $ % ^ & * () _-+ = <[] {},./? \ | ''"~
System: ESC, SPACEBAR, ENTER
Onkeydown
As of Microsoft Internet Explorer 4.0, the onkeydown event fires for the following keys:
Editing: DELETE, INSERT
Function: F1-F12
Letters: A-Z (uppercase and lowercase)
Navigation: HOME, END, left arrow, right arrow, up arrow, DOWN ARROW
Numerals: 0-9
Symbols :! @ # $ % ^ & * () _-+ = <[] {},./? \ | ''"~
System: ESC, SPACEBAR, SHIFT, TAB
As of Internet Explorer 5, the event also fires for the following keys:
Editing: BACKSPACE
Navigation: page up, PAGE DOWN
System: SHIFT + TAB
As of Internet Explorer 5, this event can be canceled for the following keys and key combinations by specifying event. returnValue = false:
Editing: BACKSPACE, DELETE
Letters: A-Z (uppercase and lowercase)
Navigation: page up, page down, END, HOME, left arrow, right arrow, up arrow, DOWN ARROW
Numerals: 0-9
Symbols :! @ # $ % ^ & * () _-+ = <[] {},./? \ | ''"~
System: SPACEBAR, ESC, TAB, SHIFT + TAB
You can cancel all keys that fire the onkeydown event in HTML Applications, including most accelerator keys, such as ALT + F4.
In Internet Explorer 4.0, you cannot cancel the onkeydown event, but you can use the onkeypress event to cancel keyboard events.
You can press the two together as follows:
Copy codeThe Code is as follows: if (window. event. shiftKey & event. keyCode = xx)
Function document_onpress ()
{
If (event. keyCode = '13 ')
{
Document. all. div_Line.style.pixelLeft = document. all. div_Line.style.pixelLeft + 1;
Document. all. div_Q.style.pixelLeft = document. all. div_Q.style.pixelLeft + 1;
Document. all. div_T.style.pixelLeft = document. all. div_T.style.pixelLeft + 1;
}