Web page
In many Web pages, you can use shortcuts to complete certain actions, such as the Discuz forum "after completion can press Ctrl+enter release" Function!
This function is done using the KeyCode method of the event attribute in JavaScript, using the onkeydown event to drive.
In JavaScript, you can pass the KeyCode property to the Asscii code value that the user presses. The specific corresponding relation may check the ASSCII code table.
Example:
CODE: [Copy to Clipboard]
--------------------------------------------------------------------------------
<script language= "JavaScript" >
<!--
Function Hotkey ()
{
var A=window.event.keycode;
if (a==65)
{
Alert ("You press a key");
}
}//End Hotkey
Document.onkeydown = Hotkey; Call hotkey function when onkeydown event occurs
-->
</SCRIPT>
In addition, in the use of shortcut keys, ALT, CTRL, SHIFT, and other auxiliary keys are often used, can be altkey, Ctrlkey, shiftkey these three properties to determine the ALT, CTRL, SHIFT key state
For example, the value of Event.ctrlkey is true, which means that the user presses the CTRL key.
Example:
CODE: [Copy to Clipboard]
--------------------------------------------------------------------------------
<script language= "JavaScript" >
<!--
Function Hotkey ()
{
if (Event.ctrlkey)
{
Alert ("You pressed the CTRL key");
}
}//End Hotkey
Document.onkeydown = Hotkey; Call hotkey function when onkeydown event occurs
-->
</SCRIPT>
Can be combined to form a real shortcut key, the execution of the statement for you want the effect on it.
CODE: [Copy to Clipboard]
--------------------------------------------------------------------------------
<script language= "JavaScript" >
<!--
Function Hotkey ()
{
var A=window.event.keycode;
if ((a==65) && (Event.ctrlkey)
{
Alert ("You press CTRL + a key");
}
}//End Hotkey
Document.onkeydown = Hotkey; Call hotkey function when onkeydown event occurs
-->
</SCRIPT>
Document.onkeydown = Hotkey statement is in the full page, when the user presses the key, call the hotkey function, perhaps you want to implement shortcut key function in the page, then, you can imitate the following do (remember to delete "Document.onkeydown = Hotkey "statement):
CODE: [Copy to Clipboard]
--------------------------------------------------------------------------------
<textarea rows= "7" cols= "name=" "Message" tabindex= "2" ></textarea>
In this way, you can use shortcut keys only if the cursor focus is in a text box.