* The callback for the keyboard event is the Document.onkeydown function, which passes in an event type parameter
Document.onkeydown = function (e) { //write callback function when event is triggered}
For details of the *evnet event, please see the document, which looks like this:
Specific URL:
Http://www.w3school.com.cn/jsref/dom_obj_event.asp
* Example Application
Requirement: Trigger Savecomment method When Ctrl+enter key is pressed
The code is:
Document.onkeydown = function (e) {//console.log (E.ctrlkey); if (= = E.keycode && e.ctrlkey) {//console.log (C1) ; Savecomment ();}}
Analysis: When CTRL is pressed, the method is triggered, the CTRL key is not released, and the method is triggered again by pressing the ENTER key.
Conjecture: 1) The internal implementation of E must have an array to store the key ID, which means that even if there are 10 buttons pressed at the same time, it can be recognized simultaneously.
At the same time, the properties of each button's object have a property that is pressed if it is pressed to true.
2) at the same time, pressing CTRL and then pressing ENTER does not simply call the onkeydown function again, but instead saves the last event that OnKeyDown has not completed (Ctrl-key pressed).
For specific practical applications, please see my article:
Welcome comments, Guidance.
JS Monitor keyboard two key combination trigger