Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Missing WM_INPUT Signals When Focusing on "Start Menu" in WPF #29

Open
HsiaoCH opened this issue Apr 26, 2024 · 1 comment
Open

Comments

@HsiaoCH
Copy link

HsiaoCH commented Apr 26, 2024

protected override void OnSourceInitialized(EventArgs e)
{
    var windowInteropHelper = new WindowInteropHelper(this);
    var hwnd = windowInteropHelper.Handle;
    var devices = RawInputDevice.GetDevices();

    RawInputDevice.RegisterDevice(HidUsageAndPage.TouchScreen,
        RawInputDeviceFlags.ExInputSink | RawInputDeviceFlags.DevNotify, hwnd);
    RawInputDevice.RegisterDevice(HidUsageAndPage.TouchPad,
        RawInputDeviceFlags.ExInputSink | RawInputDeviceFlags.DevNotify, hwnd);
    RawInputDevice.RegisterDevice(HidUsageAndPage.Pen,
        RawInputDeviceFlags.ExInputSink | RawInputDeviceFlags.DevNotify, hwnd);
    HwndSource source = HwndSource.FromHwnd(hwnd);
    source.AddHook(WndProc);
}

private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
    switch (msg)
    {
        case 0x00FF:
            {
                ProcessInputCommand(lParam);
                break;
            }
    }
    handled = false;
    return IntPtr.Zero;
}

Regardless of the triggering position, whenever focusing on the "Start Menu" in the system, the msg no longer receives the 0x00FF signal. Whether it's TouchScreen, TouchPad, or Pen, the issue persists. This has been bothering me for a long time. I would like to ask how to solve this problem, so that even when focusing on the "Start Menu" in the system, I can still receive the correct WM_INPUT signals. Thank you.

*My system is win11

@Leayal
Copy link

Leayal commented Jul 1, 2024

Long late but....

Try to use RawInputDeviceFlags.InputSink instead of RawInputDeviceFlags.ExInputSink.
ExInputSink hints OS that the WM_INPUT will only arrive to your application only when there are no other processes registered for Raw Input.

In case it doesn't work, try to run your app as Admin. Sometimes a process with higher privilege may "eat" (by setting the message to be handled) and stop the WM_PUT message for travelling to other processes.

If both doesn't work, I'm sorry I can't help much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants