Maximum call stack size exceeded

I have some code ,as follow
function triggerKeyboardEvent(element, evtType, keyCode)
var eventObj = document.createEventObject ?
document.createEventObject() : document.createEvent(“Events”);
eventObj.initEvent(evtType, true, true);
eventObj.keyCode = keyCode;
eventObj.which = keyCode;
element.dispatchEvent ? element.dispatchEvent(eventObj) : element.fireEvent(‘on’ + evtType, eventObj);

I use it to Simulae keyboard events,but the browser error:
KeyMouse-fireEvent.js:30 Uncaught RangeError: Maximum call stack size exceeded.
at fireKeyEventChrome (KeyMouse-fireEvent.js:30)

It would be cause you fire akeyboard event from keyboardevent so it will loop indefinitely

Maybe,this question is solved,thanks