KeyboardEvent.key.html (1611B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title id='desc'> KeyboardEvent Object Property: key </title> 5 <script type="text/javascript"> 6 var PassTest = function() 7 { 8 document.getElementById("testresult").firstChild.data = "PASS"; 9 } 10 11 var FailTest = function() 12 { 13 document.getElementById("testresult").firstChild.data = "FAIL"; 14 } 15 16 var EVENT = "keydown"; 17 var TARGET; 18 var ActualResult = ""; 19 var result = true; 20 21 window.onload = function(e) 22 { 23 try 24 { 25 TARGET = document.getElementById("target"); 26 TARGET.addEventListener(EVENT, TestEvent, true); 27 } 28 catch(ex) 29 { 30 FailTest(); 31 } 32 } 33 34 function TestEvent(evt) 35 { 36 if ((evt.type == EVENT) && (evt.key == "a")) 37 { 38 PassTest(); 39 } 40 else 41 { 42 FailTest(); 43 } 44 } 45 </script> 46 </head> 47 <body> 48 <h4>Test Description: KeyboardEvent Object Property key holds the key value of the key pressed</h4> 49 50 Type 'a' here: <input id="target" value=""/> 51 52 <p>Test passes if the word "PASS" appears below after typing 'a' in the above textbox using keyboard.</p> 53 <div>Test result: </div> 54 <div id='testresult'>FAIL</div> 55 </body> 56 </html>