how to distinguish touch vs mouse event from SetWindowsHookEx in c#

前端 未结 1 552
夕颜
夕颜 2021-01-26 11:56

I have found a way to listen to the mouse event, but what I really want is the touch event not mouse. They seem to share the same code. Is there any way to tell if the event was

相关标签:
1条回答
  • 2021-01-26 12:44

    The lParam argument of your hookProc callback is a pointer to an MSLLHOOKSTRUCT. It contains a very poorly documented dwExtraInfo variable, which tells you whether it was generated from a touch.

    If all of the bits in 0xFF515700 are set in dwExtraInfo, then the callback was invoked in response to a touch:

    [StructLayout(LayoutKind.Sequential)]
    struct MSLLHOOKSTRUCT
    {
        public POINT pt;
        public uint mouseData;
        public uint flags;
        public uint time;
        public IntPtr dwExtraInfo;
    }
    
    const int TOUCH_FLAG = 0xFF515700;
    bool IsTouch(IntPtr lParam)
    {
        MSLLHOOKSTRUCT hookData = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, 
            typeof(MSLLHOOKSTRUCT));
        uint extraInfo = (uint)info.dwExtraInfo.ToInt32();
        if ((extraInfo & TOUCH_FLAG) == TOUCH_FLAG)
            return true;
        return false;
    }
    
    0 讨论(0)
提交回复
热议问题