I’m developing a Rhino 8 plugin that hosts a WPF UserControl inside a docking panel using System.Windows.Forms.Integration.ElementHost. Everything works correctly in Rhino 7, but in Rhino 8 keyboard input is completely blocked inside any WPF control (TextBox …). Clicking a textbox and typing produces the Windows “ding” sound — Rhino intercepts the keystrokes for its command line instead.
Environment
Rhino 8 (latest)
Plugin target: net8.0
WPF UserControl hosted via ElementHost inside a Rhino.UI.Panels.Panel subclass
This is the real answer. McNeel developer Menno’s code from 2013 — and it still works. The fix is a HwndSource hook on the WPF control’s own window responding to WM_GETDLGCODE. It even cites the exact StackOverflow answer explaining the MFC blocker. Let me implement this cleanly:
Ran a command, read a file
Ran a command, read a file
Found the real fix — from McNeel’s own developer @menno. The entire solution is just this:
csharp
var source = HwndSource.FromVisual(_wpfControl) as HwndSource;
source.AddHook(WpfKeyboardHook);
// In the hook:
if (msg == WM_GETDLGCODE) {
handled = true;
return DLGC_WANTCHARS | DLGC_WANTARROWS | DLGC_HASSETSEL | DLGC_WANTTAB;
}