Issue With CefSharp Browser SendKeys

依然范特西╮ 提交于 2019-11-30 23:12:29

I used your code like this, and it works for me.

KeyEvent k = new KeyEvent();
k.WindowsKeyCode = 0x0D;
k.FocusOnEditableField = true;
k.IsSystemKey = false;
k.Type = KeyEventType.Char;
Browser.GetBrowser().GetHost().SendKeyEvent(k);

So much time spent, but found the accepted answer useful to get to the bottom of this:

KeyEvent k = new KeyEvent
{
    WindowsKeyCode = 0x0D, // Enter
    FocusOnEditableField = true,
    IsSystemKey = false,
    Type = KeyEventType.KeyDown
};

_browser.GetBrowser().GetHost().SendKeyEvent(k);

Thread.Sleep(100);

k = new KeyEvent
{
    WindowsKeyCode = 0x0D, // Enter
    FocusOnEditableField = true,
    IsSystemKey = false,
    Type = KeyEventType.KeyUp
};

_browser.GetBrowser().GetHost().SendKeyEvent(k);

Thread.Sleep(100);

Notice the KeyEventType.KeyDown and then KeyEventType.KeyUp is sent.

Inspired by CEF Simulate Mousedown and Keysend and CefSharp webpage element click.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!