Last Updated: February 25, 2016
· ihcsim

Create And Trigger OnKeyDown Events In QUnit

I was looking for a way to simulate "onkeydown" events in my QUnit tests. The answer lies in the JQuery Event object (

 // create and trigger onkeydown events
var upArrowKeyEvent = jQuery.Event("OnUpArrowKeyDown", 
    {keyCode: 38});

function onUpArrowKeyDownEventHandler(event) {
    if(event.keyCode == 38)
        ; // do something

For more examples on creating custom events with parameters, refer

For a list of complete keyboard keycodes, refer