Simulate mouse dragging

Having problems with building or using the CefSharp .NET binding? Ask your CEF-related questions here. Please ask general usage questions on StackOverflow.

Moderator: amaitland

Simulate mouse dragging

Postby grungeg1 » Thu Oct 22, 2020 10:50 am

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);
                }

grungeg1
Newbie
 
Posts: 6
Joined: Thu Oct 22, 2020 10:04 am

Re: Simulate mouse dragging

Postby magreenblatt » Thu Oct 22, 2020 1:29 pm

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.
magreenblatt
Site Admin
 
Posts: 10919
Joined: Fri May 29, 2009 6:57 pm

Re: Simulate mouse dragging

Postby grungeg1 » Thu Oct 22, 2020 1:40 pm

I'm not following exactly.

The code I posted is one of my failed attempts.
grungeg1
Newbie
 
Posts: 6
Joined: Thu Oct 22, 2020 10:04 am

Re: Simulate mouse dragging

Postby Czarek » Thu Oct 22, 2020 1:45 pm

Add print statements every time you call SendMouseMoveEvent and SendMouseClickEvent and print all its arguments as well.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. Connect with me on LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1913
Joined: Sun Nov 06, 2011 2:12 am

Re: Simulate mouse dragging

Postby amaitland » Thu Oct 22, 2020 2:33 pm

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
Maintainer of the CefSharp project.
amaitland
Master
 
Posts: 957
Joined: Wed Jan 14, 2015 2:35 am

Re: Simulate mouse dragging

Postby grungeg1 » Mon Oct 26, 2020 9:27 am

Thanks, will do.
grungeg1
Newbie
 
Posts: 6
Joined: Thu Oct 22, 2020 10:04 am

Re: Simulate mouse dragging

Postby grungeg1 » Thu Oct 29, 2020 10:47 am

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.
grungeg1
Newbie
 
Posts: 6
Joined: Thu Oct 22, 2020 10:04 am

Re: Simulate mouse dragging

Postby grungeg1 » Thu Oct 29, 2020 10:59 am

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;
grungeg1
Newbie
 
Posts: 6
Joined: Thu Oct 22, 2020 10:04 am

Re: Simulate mouse dragging

Postby grungeg1 » Thu Oct 29, 2020 11:00 am

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.
grungeg1
Newbie
 
Posts: 6
Joined: Thu Oct 22, 2020 10:04 am


Return to CefSharp Forum

Who is online

Users browsing this forum: No registered users and 1 guest