//鼠标事件源类型
public enum MouseEventSource { Mouse, Pen, Touch } /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); inkcv.PreviewMouseDown += Inkcv_PreviewMouseDown; inkcv.PreviewMouseMove += Inkcv_PreviewMouseMove; inkcv.PreviewMouseUp += Inkcv_PreviewMouseUp; } private void Inkcv_PreviewMouseUp(object sender, MouseButtonEventArgs e) { var s = GetMouseEventSource(); result.Text = "mouse up,Source: "+ s.ToString(); } private void Inkcv_PreviewMouseMove(object sender, MouseEventArgs e) { if (e.LeftButton==MouseButtonState.Pressed) { result.Text ="mouse move,Source: "+ GetMouseEventSource().ToString(); } } private void Inkcv_PreviewMouseDown(object sender, MouseButtonEventArgs e) { var s = GetMouseEventSource(); result.Text = "mouse previewdown,Source: "+ s.ToString(); } [DllImport("user32.dll")] private static extern uint GetMessageExtraInfo(); public static MouseEventSource GetMouseEventSource() { uint extra = GetMessageExtraInfo(); bool isTouchOrPen = ((extra & 0xffffff00) == 0xff515700); if (!isTouchOrPen) return MouseEventSource.Mouse; bool isTouch = ((extra & 0x00000080) == 0x00000080); return isTouch ? MouseEventSource.Touch : MouseEventSource.Pen; } }