SendMouseMoveEvent doesn't work

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

SendMouseMoveEvent doesn't work

Postby TheLax » Thu May 25, 2017 9:55 pm

Hi all,
I am really a newbie here, and not a native English speaker, so....... Anyway, the CEF project is excellent, thank you!

Here is my problem.
I want to simulate mouse movement to the browser. and I didn't enable the off-screen draw feature.
it seems work when I call SendMouseMoveEvent immediately after the OnPageLoadEnd callback invoked. but doesn't work after doing some other stuff.

Why? Are there any points I didn't get from SendMouseMoveEvent?

Here is the c++ code:
Code: Select all
       
if(frame->IsMain())
        {

            CefMouseEvent mouseEvent;
            mouseEvent.x = 666;
            mouseEvent.y = 666;
            mBrowser->GetHost()->SendMouseMoveEvent(mouseEvent, false); // done with it
       .... ...


And the HTML page:
Code: Select all
  <body>
      <h1>Welcome to The Cef Monkey Script Engine</h1>
      <h2>
          it's a small monkey,hope you enjoy it!
      <h2>
      <p id="debug">it's test context</p>
  </body>
  <script>
      document.onmousemove = function (e)
      {
          document.getElementById("debug").innerText ="The mouse location: ( " + e.pageX + ", " + e.pageY + " )";
      }
  </script>
TheLax
Newbie
 
Posts: 3
Joined: Thu May 25, 2017 8:20 pm

Re: SendMouseMoveEvent doesn't work

Postby Czarek » Tue May 30, 2017 12:55 pm

Maybe mouse move events are propagated to Javascript only when some time has passed between them. So if you send multiple at the same time, only the first one is send. Have you tried with some timeout?

I only used SendMouseMoveEvent in OSR mode so far.

There is API for triggering mouse events programmatically in js, but this API is marked as deprecated:
https://developer.mozilla.org/en-US/doc ... MouseEvent
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: SendMouseMoveEvent doesn't work

Postby TheLax » Tue May 30, 2017 10:44 pm

Czarek wrote:Maybe mouse move events are propagated to Javascript only when some time has passed between them. So if you send multiple at the same time, only the first one is send. Have you tried with some timeout?

I only used SendMouseMoveEvent in OSR mode so far.

There is API for triggering mouse events programmatically in js, but this API is marked as deprecated:
https://developer.mozilla.org/en-US/doc ... MouseEvent

Thank you for your reply, Czarek.
I retry my code today, it doesn't work even I call SendMouseMoveEvent only once, immediately after the OnPageLoadEnd callback.
Maybe this function is designed for OSR mode, I shouldn't use it this way.
The js solution is helpful, I never know it before, thank you!
TheLax
Newbie
 
Posts: 3
Joined: Thu May 25, 2017 8:20 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 25 guests