What does WPF use to capture mouse and keyboard input?

前端 未结 2 1344
灰色年华
灰色年华 2020-12-28 09:09

I globally (system-wide) filter certain mouse clicks using SetWindowsHookEx and WH_MOUSE_LL. The problem is it doesn\'t work for WPF applications (

相关标签:
2条回答
  • 2020-12-28 09:40

    Even if you try to set filter, .NET Framework may have some undocumented API to put WPF's filter on high priority not allowing your filter to execute at all in order to make sure WPF works correctly.

    WPF windows are same as normal window and they are supposed to work correctly with pre-existing input APIs as well as new APIs in order to make WPF work with remote desktop and other such software.

    Update:

    Windows Hook were provided in earlier windows API because that time the concepts like Event Bubbling and Preview of events were not available and for such implementations hooks were useful. WPF already provides event filtering with Preview events and bubbling of events, and that is the reason hooks may not be supported.

    Hooks are not very standard part of API because only very few applications use them. May be you can post bug at Microsoft that their filter is not allowing your hook filter.

    0 讨论(0)
  • 2020-12-28 09:42
    • WPF Window creates HwndSource (Window.CreateSourceWindow).
    • HwndSource creates HwndWrapper (HwndSource.Initialize).
    • HwndWrapper creates Win32 window with window procedure that delegate Windows messages to hooks, specified by HwndSource.
    • One hook is the HwndSource.InputFilterMessage that delegate Windows messages to four input providers: stylus, mouse, keyboard, appcommand.
    • Provider parses appropriate Windows message and invokes InputManager to raise input events on elements.

    HwndMouseInputProvider process messages such as WM_MOUSEMOVE, WM_LBUTTONDOWN, etc. So I think there is no DirectInput used to handle mouse and keyboard input.

    0 讨论(0)
提交回复
热议问题