判断Mouse事件源类型
Posted tianping
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了判断Mouse事件源类型相关的知识,希望对你有一定的参考价值。
//鼠标事件源类型
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; } }
以上是关于判断Mouse事件源类型的主要内容,如果未能解决你的问题,请参考以下文章
ActionScript 3 actionscript 3 - 按钮动作[听多个事件。例如。 MOUSE_OVER,MOUSE_OUT,MOUSE_UP]