简体   繁体   中英

Use mouse click in awesomium (c#)

I'm using awesomium and I'm trying to utilize the command "InjectMouseDown." unfortunately nothing happens. I am trying with the following code:

private void newbrowser()
        {
            dir = "C:\\AwCache\\" + RandomString(10);

            _webView = WebCore.CreateWebView(800, 600);
            _webView.ParentWindow = this.Handle;
            using (WebSession session = WebCore.CreateWebSession(dir, new WebPreferences() { /*CustomCSS = "body { zoom: 75%; }", ProxyConfig = proxyok,*/ }))
            {
                _webView.Source = new Uri("http://www.google.com");
                _webView.DocumentReady += WebViewOnDocumentReady;
            }
        }
private void WebViewOnDocumentReady(object sender, UrlEventArgs urlEventArgs)
        {
            timer1.Enabled = true;
        }
private void timer1_Tick(object sender, EventArgs e)
        {
                _webView.InjectMouseMove(5, 100);
                _webView.InjectMouseDown(MouseButton.Left);
}

In timer1_tick, add the InjectMouseUp(MouseButton.Left); as well. Once I injected all the three mouse events (InjectMouseMove,InjectMouseDown,InjectMouseUp) into WebView it worked.

Below is the sample code which worked for me (though written in C++).

 void Containerclass::mousePressed(ofMouseEventArgs &e)
 {
   webview->InjectMouseMove(e.x - loc.x, e.y - loc.y); 
   webview->InjectMouseDown(MouseButton_Left);
   webview->InjectMouseUp(MouseButton_Left);
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM