Simulate KeyDown with KeyEvent and ctrl combination

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.

Simulate KeyDown with KeyEvent and ctrl combination

Postby vinarts » Mon Dec 25, 2017 2:11 pm

I want a KeyEvent on my CefSharp Browser named Browser to receive a CTRL + Right-arrow and in another case CTRL + Left-arrow. How can I release that because my current code won't work for this unfortunately. I am developing with C# on WinForms.

Code: Select all
KeyEvent k = new KeyEvent();
k.WindowsKeyCode = 0x0D;
k.FocusOnEditableField = true;
k.IsSystemKey = false;
k.Type = KeyEventType.KeyDown;
Browser.GetBrowser().GetHost().SendKeyEvent(k);
vinarts
Newbie
 
Posts: 3
Joined: Mon Dec 25, 2017 1:17 pm

Re: Simulate KeyDown with KeyEvent and ctrl combination

Postby Czarek » Tue Dec 26, 2017 6:21 am

You should ask this question on CefSharp support channel. First you have to send key down for control key (VK_LCONTROL) and then key down for right arrow.
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: Simulate KeyDown with KeyEvent and ctrl combination

Postby vinarts » Tue Dec 26, 2017 6:34 am

Czarek wrote:You should ask this question on CefSharp support channel. First you have to send key down for control key (VK_LCONTROL) and then key down for right arrow.

To first send control and then right arrow I changed my code a little bit:
Code: Select all
 //KeyEvent for CTRL
                KeyEvent k = new KeyEvent();
                 k.WindowsKeyCode = 0xA2;
                       k.FocusOnEditableField = true;
                k.IsSystemKey = false;
                k.Type = KeyEventType.KeyDown;

                //KeyEvent for Right-arrow
                KeyEvent k2 = new KeyEvent();
                k2.WindowsKeyCode = 0x27;
                k2.FocusOnEditableField = true;
                k2.IsSystemKey = false;
                k2.Type = KeyEventType.KeyDown;

                //Perform CTRL and then Right-arrow key
                Browser.GetBrowser().GetHost().SendKeyEvent(k);
                Browser.GetBrowser().GetHost().SendKeyEvent(k2);

But the problem is that they aren't simulated at the same time which means my browser doesn't recognize it as the shortcut CTRL + right arrow.
What can I do? Thanks for any help!
vinarts
Newbie
 
Posts: 3
Joined: Mon Dec 25, 2017 1:17 pm

Re: Simulate KeyDown with KeyEvent and ctrl combination

Postby vinarts » Tue Jan 09, 2018 4:40 pm

Is there anybody who could help?
vinarts
Newbie
 
Posts: 3
Joined: Mon Dec 25, 2017 1:17 pm

Re: Simulate KeyDown with KeyEvent and ctrl combination

Postby amaitland » Tue Jan 09, 2018 5:39 pm

Control is a modifier. So you need to set the Modifiers property.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1292
Joined: Wed Jan 14, 2015 2:35 am


Return to Support Forum

Who is online

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