diff --git a/CefSharp.WinForms.Example/Handlers/KeyboardHandler.cs b/CefSharp.WinForms.Example/Handlers/KeyboardHandler.cs index 329f64291..1d992a878 100644 --- a/CefSharp.WinForms.Example/Handlers/KeyboardHandler.cs +++ b/CefSharp.WinForms.Example/Handlers/KeyboardHandler.cs @@ -16,21 +16,25 @@ namespace CefSharp.WinForms.Example.Handlers const int WM_CHAR = 0x102; const int WM_SYSCHAR = 0x106; const int VK_TAB = 0x9; - - bool result = false; + const int VK_LEFT = 0x25; + const int VK_UP = 0x26; + const int VK_RIGHT = 0x27; + const int VK_DOWN = 0x28; isKeyboardShortcut = false; // Don't deal with TABs by default: // TODO: Are there any additional ones we need to be careful of? // i.e. Escape, Return, etc...? - if (windowsKeyCode == VK_TAB) + if (windowsKeyCode == VK_TAB || windowsKeyCode == VK_LEFT || windowsKeyCode == VK_UP || windowsKeyCode == VK_DOWN || windowsKeyCode == VK_RIGHT) { - return result; + return false; } - Control control = browserControl as Control; - int msgType = 0; + var result = false; + + var control = browserControl as Control; + var msgType = 0; switch (type) { case KeyType.RawKeyDown: @@ -69,17 +73,23 @@ namespace CefSharp.WinForms.Example.Handlers } // 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: - PreProcessControlState state = PreProcessControlState.MessageNotNeeded; + 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(() => { - Message msg = new Message() { HWnd = control.Handle, Msg = msgType, WParam = new IntPtr(windowsKeyCode), LParam = new IntPtr(nativeKeyCode) }; + 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. - bool processed = Application.FilterMessage(ref msg); + var processed = Application.FilterMessage(ref msg); if (processed) { state = PreProcessControlState.MessageProcessed; @@ -92,6 +102,7 @@ namespace CefSharp.WinForms.Example.Handlers state = control.PreProcessControlMessage(ref msg); } })); + if (state == PreProcessControlState.MessageNeeded) { // TODO: Determine how to track MessageNeeded for OnKeyEvent. @@ -102,16 +113,18 @@ namespace CefSharp.WinForms.Example.Handlers // Most of the interesting cases get processed by PreProcessControlMessage. result = true; } - Debug.WriteLine(String.Format("OnPreKeyEvent: KeyType: {0} 0x{1:X} Modifiers: {2}", type, windowsKeyCode, modifiers)); - Debug.WriteLine(String.Format("OnPreKeyEvent PreProcessControlState: {0}", state)); + + Debug.WriteLine("OnPreKeyEvent: KeyType: {0} 0x{1:X} Modifiers: {2}", type, windowsKeyCode, modifiers); + Debug.WriteLine("OnPreKeyEvent PreProcessControlState: {0}", state); + return result; } /// > public bool OnKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey) { - bool result = false; - Debug.WriteLine(String.Format("OnKeyEvent: KeyType: {0} 0x{1:X} Modifiers: {2}", type, windowsKeyCode, modifiers)); + var result = false; + Debug.WriteLine("OnKeyEvent: KeyType: {0} 0x{1:X} Modifiers: {2}", type, windowsKeyCode, modifiers); // TODO: Handle MessageNeeded cases here somehow. return result; }