c# - Simulating real key strokes on an inactive webrowser control -


i have c# winforms app webbrowser control embedded website automation. need send programatically keyboard strokes within app embedded webbrowser control even when app hidden or not focused. setting text html text boxes works not (i.e. html form angularjs validation ignores it's not real typing suppose).

i've spent 2 weeks searching , trying different approches:

  • sendinput or sendkeys: works fine when app foregrounded (not good).

  • raising onkeydown , onkeypress events: not working me @ form level , @ webbrowser control level.

  • raising keydown,keypress, keyup events jquery in dom: no success.

is there @ solution this? thanks

after lot of trial , error found solution. angularjs form validation mechanism waits "change" event happen (and not keydown,keyup,keypress). trigger event wasn't easy (jquery.trigger didn't job). injected following function in webbrowser control , invoked it.

setinputtext = function (id, str, x) {      var el = $('#' + id);      if (typeof x === "undefined") {          x = 0;          el.focus();      }      if (x >= str.length) {           el.blur();          return;      }            var c = str.charat(x);      el.val(el.val() + c);        //this magic: trigger change event in pure js      var evt = document.createevent("htmlevents");      evt.initevent("change", false, true);      el[0].dispatchevent(evt);                //type each character every 75ms      settimeout(function () { setinputtext(id, str, ++x); }, 75);      return;  }


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -