Anonymous - 2012-06-08

I did some further testing and in the keydown keypress event the args e.which || e.charCode || e.keyCode always return 0, ... I also tried with some patching in de watin code.

in IEFireEventHandler

private string CreateJavaScriptFireEventCode(NameValueCollection eventObjectProperties, string eventName)
{
var scriptCode = new StringBuilder();
var window = _ieElement.ParentWindow;
if (IE.GetMajorIEVersion() > 8 && eventName.ToLower().Contains("key"))
{
scriptCode.Append("var newEvt = document.createEvent('KeyboardEvent');");

            //init keyboardevent
            scriptCode.AppendFormat("newEvt.initKeyboardEvent('{0}',true, true, null, false, false, false, false, null, {1});", eventName.ToLower().Replace("on", ""), eventObjectProperties.GetValues(0)[0]);

            var reference = _ieElement.GetJavaScriptElementReference();
            scriptCode.AppendFormat("{0}.dispatchEvent(newEvt);", reference);
        }
        else
        {
            scriptCode.Append("var newEvt = document.createEventObject();");
            CreateJavaScriptEventObject(scriptCode, eventObjectProperties);

            var reference = _ieElement.GetJavaScriptElementReference();
            scriptCode.Append(string.Format("{0}.fireEvent('{1}', newEvt);", reference, eventName));
        }

        return scriptCode.ToString();
    }