Key event simulation test

by lddubeau

HTML

<script src="http://bililite.com/inc/jquery.sendkeys.js"></script>
<script src="http://bililite.com/inc/bililiteRange.js"></script>
<label>Test input:<input type="text" value="" id="eventTarg"></label>
<p>Type in the input or press one of the buttons. Note the event log, below</p>
<button id="simA_plain">Simulate "A", no plugin</button>
<button id="simB_plugin">Simulate "B", using the plugin</button>
<hr>
<div id="eventLog"></div>

CSS

body {margin: 1em;}

JavaScript

$("#eventTarg").bind ("keydown keypress keyup change",  function (zEvent) {
    console.log ("Input event:", zEvent.type, zEvent);
    $("#eventLog").append ('<span>' + zEvent.type + ': ' + zEvent.which + ', </span>');
} );

$("button").click ( function (zEvent) {
    if (zEvent.target.id == "simA_plain") {
        console.log ("Plain");
        var keyVal = 65;
        $("#eventTarg").trigger ( {
            type: 'keypress', keyCode: keyVal, which: keyVal, charCode: keyVal
        } );
    }
    else {
        console.log ("Plugin");
        $("#eventTarg").sendkeys ("B") ;
    }
} );