zoukankan      html  css  js  c++  java
  • Geckofx 45 正确模拟键盘输入的事件绑定方法

              var inputs = selection.GetElementsByTagName("input").Select(p => p as Gecko.DOM.GeckoInputElement).Where(p => p.GetAttribute("placeholder") == "Stake");
                        foreach (var input in inputs)
                        {
                            var curInput = input as Gecko.DOM.GeckoInputElement;
    
                            //curInput.SetAttribute("value", bet.BetAmount.ToString("0"));
                            #region
                            DomEventArgs ev = myGeckoWebBrowser.Document.CreateEvent("KeyEvents");
                            var webEvent = new Event(myGeckoWebBrowser.Window.DomWindow, ev.DomEvent as nsISupports);
                            //add focus event
                            webEvent.InitEvent("focus", true, false);
                            curInput.GetEventTarget().DispatchEvent(ev);
                            //.46
                            //0-9  48~57
                            //add keypress event
                            var nsIEventVar = ((nsIDOMKeyEvent)ev.DomEvent);
                            char[] amountChars = bet.BetAmount.ToString().ToCharArray();
                            foreach (var vchar in amountChars)
                            {
                                int keyCode = CommonHelper.ToKeyValue(vchar);
                                nsIEventVar.InitKeyEvent(new nsAString("keypress"), true, false, myGeckoWebBrowser.Window.DomWindow, false, false, false, false, (uint)keyCode, (uint)keyCode);
                                Xpcom.QueryInterface<nsIDOMEventTarget>(curInput.DomObject).DispatchEvent(nsIEventVar);
                            }
                            //add blur event
                            webEvent.InitEvent("blur", true, false);
                            curInput.GetEventTarget().DispatchEvent(ev);
                            #endregion
                            Application.DoEvents();
                            isetAmount = true;
                        }
    

      

  • 相关阅读:
    Docker
    Web
    爬虫
    Python
    软件脱壳
    网络抓包
    HTTPS单向认证,双向认证
    新版无完整背景图片滑块验证码
    Frida Hook
    闭包函数与装饰器
  • 原文地址:https://www.cnblogs.com/mschen/p/6768306.html
Copyright © 2011-2022 走看看