CEFSharp-CEF搜索对话框?

时间:2018-11-01 17:02:02

标签: c# cefsharp chromium-embedded

CEFSHARP是否可以进行CTRL + F样式搜索?我知道id必须手动创建对话框,但是如何获得实际执行的操作?如果我键入“ test”,它将在chrome中工作,并突出显示所有“ test”。

我已经有一个键盘挂钩设置,因此我可以很容易地实现CTRL + F热键,但是我不确定实际进行搜索的方式。

如果有帮助,这里是热键键盘挂钩:

list_a

要使用此挂钩,请在您的public class KeyboardHandler : IKeyboardHandler { public bool OnPreKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut) { const int WM_SYSKEYDOWN = 0x104; const int WM_KEYDOWN = 0x100; const int WM_KEYUP = 0x101; const int WM_SYSKEYUP = 0x105; const int WM_CHAR = 0x102; const int WM_SYSCHAR = 0x106; const int VK_TAB = 0x9; const int VK_LEFT = 0x25; const int VK_UP = 0x26; const int VK_RIGHT = 0x27; const int VK_DOWN = 0x28; isKeyboardShortcut = false; if (windowsKeyCode == VK_TAB || windowsKeyCode == VK_LEFT || windowsKeyCode == VK_UP || windowsKeyCode == VK_DOWN || windowsKeyCode == VK_RIGHT) { return false; } var control = browserControl as Control; var msgType = 0; switch (type) { case KeyType.RawKeyDown: if (isSystemKey) { msgType = WM_SYSKEYDOWN; } else { msgType = WM_KEYDOWN; } break; case KeyType.KeyUp: if (isSystemKey) { msgType = WM_SYSKEYUP; } else { msgType = WM_KEYUP; } break; case KeyType.Char: if (isSystemKey) { msgType = WM_SYSCHAR; } else { msgType = WM_CHAR; } break; default: Trace.Assert(false); break; } // We have to adapt from CEF's UI thread message loop to our fronting WinForm control here. // So, we have to make some calls that Application.Run usually ends up handling for us: var state = PreProcessControlState.MessageNotNeeded; // We can't use BeginInvoke here, because we need the results for the return value // and isKeyboardShortcut. In theory this shouldn't deadlock, because // atm this is the only synchronous operation between the two threads. control.Invoke(new Action(() => { var msg = new Message { HWnd = control.Handle, Msg = msgType, WParam = new IntPtr(windowsKeyCode), LParam = new IntPtr(nativeKeyCode) }; // First comes Application.AddMessageFilter related processing: // 99.9% of the time in WinForms this doesn't do anything interesting. if (Application.FilterMessage(ref msg)) { state = PreProcessControlState.MessageProcessed; } else { // Next we see if our control (or one of its parents) // wants first crack at the message via several possible Control methods. // This includes things like Mnemonics/Accelerators/Menu Shortcuts/etc... state = control.PreProcessControlMessage(ref msg); } })); if (state == PreProcessControlState.MessageNeeded) { isKeyboardShortcut = true; } else if (state == PreProcessControlState.MessageProcessed) { return true; } return false; } public bool OnKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey) { if (type == KeyType.KeyUp) { Keys key = (Keys)windowsKeyCode; if (modifiers == CefEventFlags.ControlDown && key == Keys.F) { //CTRL+F Hit return true; } } return false; } } 对象上使用ChromiumWebBrowser的公共属性,只需将其设置为KeyboardHandler,其中new KeyboardHandler()是上面的类代码

0 个答案:

没有答案