Page 1 of 1

Simulate mouse dragging

PostPosted: Thu Oct 22, 2020 10:50 am
by grungeg1
I have an offscreen cef render context which I use as a texture in OpenGL.


I support mouse gestures on this texture, and I get those mouse gestures as a stream of (bool, int, int) structs for whether the trigger is pressed and the pixel values. Using SendMouseClickEvent, I can get clicking behavior to work, I also can get the mouse to hover.

However, for sliders, and other things which require the mouse to be depressed while pulling them, the best I can do is click the position. i can't get the mouse to click, hold and drag the slider around.

My implementation of the menu supports animations and is doing 30fps, so I would like to be able to be able to get the full extent of Left mouse button functionality if possible.


I haven't seen much on this, so any help is appreciated.


Here's the current implementation. m_iMouseState is used as a bool. Note that this example uses the CefSharp library, but the forwarding from Cefsharp to CEF is pretty simple, so it ought to translate directly to the typical CefBrowserHost::SendMouseMove type code.

Code: Select all

                if(mode == m_iPrevMouseState && m_iMouseState == 1)
                {
                    _browser.GetBrowserHost().SendMouseMoveEvent(x, y, false, CefEventFlags.LeftMouseButton);
                }
                else
                {
                    _browser.GetBrowserHost().SendMouseClickEvent(x, y, MouseButtonType.Left, !(m_iMouseState > 0), 1, CefEventFlags.None);
                }


Re: Simulate mouse dragging

PostPosted: Thu Oct 22, 2020 1:29 pm
by magreenblatt
Does it work in cefclient with --off-screen-rendering-enabled? If so, you can look at what calls it's making and do the same in your application.

Re: Simulate mouse dragging

PostPosted: Thu Oct 22, 2020 1:40 pm
by grungeg1
I'm not following exactly.

The code I posted is one of my failed attempts.

Re: Simulate mouse dragging

PostPosted: Thu Oct 22, 2020 1:45 pm
by Czarek
Add print statements every time you call SendMouseMoveEvent and SendMouseClickEvent and print all its arguments as well.

Re: Simulate mouse dragging

PostPosted: Thu Oct 22, 2020 2:33 pm
by amaitland
The CefSharp WPF implementation uses OSR, you can add debug statements to workout exactly what sequence is required.

https://github.com/cefsharp/CefSharp/bl ... r.cs#L2226

Re: Simulate mouse dragging

PostPosted: Mon Oct 26, 2020 9:27 am
by grungeg1
Thanks, will do.

Re: Simulate mouse dragging

PostPosted: Thu Oct 29, 2020 10:47 am
by grungeg1
OK, I'm now replicating the calls for the mouse behavior in OSR. I'm still not seeing the dragging behavior. Clicking works. I've tested this with two versions of CEF/CefSharp.

I'm using SendMouseMoveEvent and SendMouseClickEvent in coordination. Clicks are sent when the mouse is pressed and depressed. movement is sent otherwise. The LeftMouseButton flag is set when the mouse is held down.

Re: Simulate mouse dragging

PostPosted: Thu Oct 29, 2020 10:59 am
by grungeg1
Code: Select all
//Prim refers to an ID I use to index browsers. mode is 0 or 1 for whether the device is depressed or undepressed
ChromiumWebBrowser _browser = m_UsedBrowsers.GetObject(hPrim);

if(m_prevClickedPrim != hPrim)
{
   ChromiumWebBrowser _oldBrowser = m_UsedBrowsers.GetObject(hPrim);
 
   if(m_prevMouseState >= 1)
      _oldBrowser.GetBrowserHost().SendMouseClickEvent(x, y, MouseButtonType.Left, true, 1, CefEventFlags.None);

   if(mode >= 1)
       _browser.GetBrowserHost().SendMouseClickEvent(x, y, MouseButtonType.Left, false, 1, CefEventFlags.LeftMouseButton);

    _browser.GetBrowserHost().SetFocus(true);
}
else
{
   if(mode != m_prevMouseState)
       _browser.GetBrowserHost().SendMouseClickEvent(x, y, MouseButtonType.Left, mode == 0, 1, mode == 0 ? CefEventFlags.None : CefEventFlags.LeftMouseButton);
   else
      _browser.GetBrowserHost().SendMouseMoveEvent(x, y, false, mode == 0 ? CefEventFlags.None : CefEventFlags.LeftMouseButton);
}

m_prevMouseState = mode;
m_prevClickedPrim = hPrim;

Re: Simulate mouse dragging

PostPosted: Thu Oct 29, 2020 11:00 am
by grungeg1
so mode==0 is undepressed and mode==1 is undepressed. I'm wondering if there's an additional api call I have to make to get this to work.