C # learning notes-KeyDown, KeyPress, KeyUp events, and KeyCode, KeyData, KeyValue, and KeyChar attributes,
I didn't plan to write it separately, but when I tested the mini-program myself, the more I wrote and found that I was not clear about it, the more I learned from it. So my practice once again proved that I had to think about it on paper, I am sure you want to do this!
Directly paste the Code:
1 // order of occurrence: keyDown-> KeyPress-> KeyUp
Test Results:In IE:> Supports keyCode.> Which and charCode are not supported. Their values are undefined.In Firefox:> Supports keyCode. Except for function keys, other key values are always 0.> Which and charCode are supported. The values are the same.In Opera:> Supports keyCode and which with the same values.> CharCode is not supported and its value is undefined
Window. event. keyCode is compatible with the specific implementation code of IE and Firefox as follows. If you are interested, refer to the following HTML code.
The Code is as follows:
Javascript code
The Code is as follows:
Function keyNumAll (evt ){// Compatible with IE and Firefox to obtain keyBoardEvent objectsEvt = (evt )? Evt: (window. event )? Window. event :"");Var key = evt. keyCode
Test the compatibility of keyCode, which, and charCode in Keyboard Events
Test Results:
In IE:
> Supports keyCode.
> Which and charCode are not supported. Their values are undefined.
In Firefox:
> Supports keyCode. Except for function keys, other key values are always 0.
> Which and charCode are supported. The values are the same.
In Opera:
> Supports
Event. keyCode value table in JavascriptKey value for letters and numbers)Key code key codeA65 J 74 S 83 1 49B 66 K 75 T 84 2 50C 67 L 76 U 85 3 51D 68 M 77 V 86 4 52E 69 N 78 W 87 5 53F 70 O 79X88 6 54G 71 P 80 Y 89 7 55H 72 Q 81 Z 90 8 56I 73 R 82 0 48 9 57KeyCode function keyCode)Key code key code096 8 104 F1 112 F7 1181 97 9 105 F2 113 F8 1192 98*106 F3 114 F9 1203 99 + 107 F4 115 F10 1214 100 Enter 108
The difference between keyvalue and Keydata and KeyCode (turn)KeyPress eventsKeyPressEventArgs parametersHandled/Whether the KeyPress event has been processedKeyChar//press the key corresponding to the characterIf I, then Keychar is I, if shift+i, then Keychar is I.If it is ctrl+i, or alt+i, it will not get a KeyPress event, because they are special key sequences, not sent by KeyPress.Need KeyDownKeyDownKeyEventArgs parametersAlt gets a value that ind
The native JS event object has a value of three keyboard events:1) CharCode: The Unicode value of the clicked key2) KeyCode: ASCII decimal value of the clicked key3) which: Alphanumeric key charcode or keycode, you can try it yourselfOnce the MooTools event is encapsulated, it is unified into code and key:?
12
event.code = event.which || event.keyCode;event.key = String.fromCharCode(cod
When the user presses the ENTER key, the KeyEvent () function is executed. Can do a carriage return to submit the form, or other events!KeyCode is the code that returns the key to the KeyDown what KeyUp event occurred, and the Unicode character of the KeyPress event, and if you want to use a key combination, you can take advantage of event.ctrlkey,event.shiftkey,event. Altkey determines whether the CTRL key, the SHIFT key, and the ALT key are pressed.
Test results:
Under IE:
>> Support KeyCode
>> does not support which and charcode, the values are undefined
Under Firefox:
>> supports keycode, except function keys, the other key values are always 0
>> supports which and charcode, the values are the same
Under Opera:
>> supports KeyCode and which, the values are the same
>> does not support charcode, value is
The first way to link with href:
[javascript] View Plain copy functionaddtab (title,url) { if (' #tt '). Tabs (' exists ', title) { $ (' #tt ') . Tabs (' select ', title); }else{ $ (' #tt '). Tabs (' Add ',{ title:title, Content shown in Href:url,//tab closable:true NBSP;NBSP;NBSP;NBSP;NBSP;NBSP;NBSP;NBSP;NBSP;NBSP;NBSP}); } } The second type is in the form of an IFRAME:
Functionaddtab (title,url) { if (' #tt '). Tabs (' exists ', title
Tag: event. keycode
Set the event object when keydown occurs. The keycode is an attribute of the event object, which specifies the Unicode encoding code generated by the hitting key.
The above method is parsed:
Press Enter: 8 delete: 46 direction keys left: 37 direction keys right: 39
Top of the keyboard: 0-9: 48-57 keypad number key: 0-9: 96-105
The logic of the above method is: if it is not a digit → ba
Window. event. keycode,
However, we can use event. Which instead. However, to make it more universally compatible, it is best to use event. keycode | event. Which.
A simple example is as follows:
// JavaScript document
**************************************** ******************************Use JavaScript to intercept keyboard input on the web pageUse the keycode attribute of the event object to determine the Input key valueEg: If (event. keycode = 13) Alert ("Enter !");Key value tableA 0x65 u 0x85B 0x66 v 0x86C 0x67 w 0x87D 0x68X0x88E 0x69 Y 0x89F 0x70 Z 0x90G 0x71 0 0x48H 0x72 1 0x49I 0x73 2 0x5
, logical pixels, devices like silverhalide, PPI, ViewportMobile Soft keyboard keycode get only KeyUp and KeyDown to get, others are not, or have compatibility issues.There is also a general input too fast or too much input to the text box, and the input of Chinese, etc. will appear 229, so this is also the problem,So I don't think it's necessary to use it, because it doesn't want to use it as accurately as the PC side.The appearance of the soft keybo
Data annotation Attributes -- Key [Code-First series], -- keycode-first
The Key feature can be used in class attributes. The default Code-First Convention creates a primary Key with the attribute name "Id" or the class name + Id.
The Key feature overrides this default convention. You can apply the Key feature to a class attribute. No matter what the attribute name is, you can create a primary Key.
Let's take a look at the following code:
using System;
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.