2017-09-06 104 views
1

我的筆記本電腦上有一個鼠標和一個觸摸板。我想要一個mousemove的全局鉤子,它告訴我不僅是新的位置,還有它來自的物理設備。只訂閱觸摸板將是一個更好的解決方案,因爲我只對觸摸板感興趣。該掛鉤必須在系統範圍內工作(即使我的應用程序不在焦點中)。如何區分多個鼠標設備的鼠標移動輸入?

我該怎麼做?

我不害怕使用的PInvoke在我的C#/ WPF應用程序

回答

1

你可以使用 P-Invoke user32.getrawinputdeviceinfo。 對於鼠標輸入,你可以得到這樣的事情:

[StructLayout(LayoutKind.Sequential)] 
internal struct RID_DEVICE_INFO_MOUSE 
{ 
    [MarshalAs(UnmanagedType.U4)] 
    public int dwId; 
    [MarshalAs(UnmanagedType.U4)] 
    public int dwNumberOfButtons; 
    [MarshalAs(UnmanagedType.U4)] 
    public int dwSampleRate; 
    [MarshalAs(UnmanagedType.U4)] 
    public int fHasHorizontalWheel; 
} 

和有關設備:

StructLayout(LayoutKind.Sequential)] 
internal struct RID_DEVICE_INFO_HID 
{ 
    [MarshalAs(UnmanagedType.U4)] 
    public int dwVendorId; 
    [MarshalAs(UnmanagedType.U4)] 
    public int dwProductId; 
    [MarshalAs(UnmanagedType.U4)] 
    public int dwVersionNumber; 
    [MarshalAs(UnmanagedType.U2)] 
    public ushort usUsagePage; 
    [MarshalAs(UnmanagedType.U2)] 
    public ushort usUsage; 
}