【问题标题】:Windows 8 - Simulate gesture on resistive Touch Screen using c#Windows 8 - 使用 c# 在电阻式触摸屏上模拟手势
【发布时间】:2014-09-30 06:38:23
【问题描述】:

有没有办法使用映射到 C# 接口的物理键盘键在电阻式触摸屏设备上模拟 Windows 8 手势(缩放、旋转、滑动)?

我的设置是用于 2 种屏幕类型(电阻式和电容式触摸屏)的经典桌面 Windows 8 应用程序。在电阻式屏幕上,无法识别多点触控手势,可以使用键盘组合或映射键(此设备上未连接鼠标)来完成。

【问题讨论】:

    标签: c# windows-8 touch gesture hardware-interface


    【解决方案1】:

    Windows 8 提供了本机 touch injection 函数 InitializeTouchInjectionInjectTouchInput,您可以从 C# 中调用它们来合成可以转换为手势的指针输入。

    Input: Touch injection sample 用 C++ 演示了这一点。

    PInvoke Interop Assistant生成的p-invoke签名

    public partial class NativeConstants {
    
        /// TOUCH_FLAG_NONE -> 0x00000000
        public const int TOUCH_FLAG_NONE = 0;
    
        /// TOUCH_MASK_NONE -> 0x00000000
        public const int TOUCH_MASK_NONE = 0;
    
        /// TOUCH_MASK_CONTACTAREA -> 0x00000001
        public const int TOUCH_MASK_CONTACTAREA = 1;
    
        /// TOUCH_MASK_ORIENTATION -> 0x00000002
        public const int TOUCH_MASK_ORIENTATION = 2;
    
        /// TOUCH_MASK_PRESSURE -> 0x00000004
        public const int TOUCH_MASK_PRESSURE = 4;
    
        /// POINTER_FLAG_NONE -> 0x00000000
        public const int POINTER_FLAG_NONE = 0;
    
        /// POINTER_FLAG_NEW -> 0x00000001
        public const int POINTER_FLAG_NEW = 1;
    
        /// POINTER_FLAG_INRANGE -> 0x00000002
        public const int POINTER_FLAG_INRANGE = 2;
    
        /// POINTER_FLAG_INCONTACT -> 0x00000004
        public const int POINTER_FLAG_INCONTACT = 4;
    
        /// POINTER_FLAG_FIRSTBUTTON -> 0x00000010
        public const int POINTER_FLAG_FIRSTBUTTON = 16;
    
        /// POINTER_FLAG_SECONDBUTTON -> 0x00000020
        public const int POINTER_FLAG_SECONDBUTTON = 32;
    
        /// POINTER_FLAG_THIRDBUTTON -> 0x00000040
        public const int POINTER_FLAG_THIRDBUTTON = 64;
    
        /// POINTER_FLAG_FOURTHBUTTON -> 0x00000080
        public const int POINTER_FLAG_FOURTHBUTTON = 128;
    
        /// POINTER_FLAG_FIFTHBUTTON -> 0x00000100
        public const int POINTER_FLAG_FIFTHBUTTON = 256;
    
        /// POINTER_FLAG_PRIMARY -> 0x00002000
        public const int POINTER_FLAG_PRIMARY = 8192;
    
        /// POINTER_FLAG_CONFIDENCE -> 0x00004000
        public const int POINTER_FLAG_CONFIDENCE = 16384;
    
        /// POINTER_FLAG_CANCELED -> 0x00008000
        public const int POINTER_FLAG_CANCELED = 32768;
    
        /// POINTER_FLAG_DOWN -> 0x00010000
        public const int POINTER_FLAG_DOWN = 65536;
    
        /// POINTER_FLAG_UPDATE -> 0x00020000
        public const int POINTER_FLAG_UPDATE = 131072;
    
        /// POINTER_FLAG_UP -> 0x00040000
        public const int POINTER_FLAG_UP = 262144;
    
        /// POINTER_FLAG_WHEEL -> 0x00080000
        public const int POINTER_FLAG_WHEEL = 524288;
    
        /// POINTER_FLAG_HWHEEL -> 0x00100000
        public const int POINTER_FLAG_HWHEEL = 1048576;
    
        /// POINTER_FLAG_CAPTURECHANGED -> 0x00200000
        public const int POINTER_FLAG_CAPTURECHANGED = 2097152;
    
        /// POINTER_FLAG_HASTRANSFORM -> 0x00400000
        public const int POINTER_FLAG_HASTRANSFORM = 4194304;
    }
    
    public enum tagPOINTER_INPUT_TYPE {
    
        /// PT_POINTER -> 0x00000001
        PT_POINTER = 1,
    
        /// PT_TOUCH -> 0x00000002
        PT_TOUCH = 2,
    
        /// PT_PEN -> 0x00000003
        PT_PEN = 3,
    
        /// PT_MOUSE -> 0x00000004
        PT_MOUSE = 4,
    
        /// PT_TOUCHPAD -> 0x00000005
        PT_TOUCHPAD = 5,
    }
    
    public enum tagPOINTER_BUTTON_CHANGE_TYPE {
    
        POINTER_CHANGE_NONE,
    
        POINTER_CHANGE_FIRSTBUTTON_DOWN,
    
        POINTER_CHANGE_FIRSTBUTTON_UP,
    
        POINTER_CHANGE_SECONDBUTTON_DOWN,
    
        POINTER_CHANGE_SECONDBUTTON_UP,
    
        POINTER_CHANGE_THIRDBUTTON_DOWN,
    
        POINTER_CHANGE_THIRDBUTTON_UP,
    
        POINTER_CHANGE_FOURTHBUTTON_DOWN,
    
        POINTER_CHANGE_FOURTHBUTTON_UP,
    
        POINTER_CHANGE_FIFTHBUTTON_DOWN,
    
        POINTER_CHANGE_FIFTHBUTTON_UP,
    }
    
    [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
    public struct tagPOINTER_INFO {
    
        /// POINTER_INPUT_TYPE->DWORD->unsigned int
        public uint pointerType;
    
        /// UINT32->unsigned int
        public uint pointerId;
    
        /// UINT32->unsigned int
        public uint frameId;
    
        /// POINTER_FLAGS->UINT32->unsigned int
        public uint pointerFlags;
    
        /// HANDLE->void*
        public System.IntPtr sourceDevice;
    
        /// HWND->HWND__*
        public System.IntPtr hwndTarget;
    
        /// POINT->tagPOINT
        public Point ptPixelLocation;
    
        /// POINT->tagPOINT
        public Point ptHimetricLocation;
    
        /// POINT->tagPOINT
        public Point ptPixelLocationRaw;
    
        /// POINT->tagPOINT
        public Point ptHimetricLocationRaw;
    
        /// DWORD->unsigned int
        public uint dwTime;
    
        /// UINT32->unsigned int
        public uint historyCount;
    
        /// INT32->int
        public int inputData;
    
        /// DWORD->unsigned int
        public uint dwKeyStates;
    
        /// UINT64->unsigned __int64
        public ulong PerformanceCount;
    
        /// POINTER_BUTTON_CHANGE_TYPE->tagPOINTER_BUTTON_CHANGE_TYPE
        public tagPOINTER_BUTTON_CHANGE_TYPE ButtonChangeType;
    }
    
    [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
    public struct tagPOINTER_TOUCH_INFO {
    
        /// POINTER_INFO->tagPOINTER_INFO
        public tagPOINTER_INFO pointerInfo;
    
        /// TOUCH_FLAGS->UINT32->unsigned int
        public uint touchFlags;
    
        /// TOUCH_MASK->UINT32->unsigned int
        public uint touchMask;
    
        /// RECT->tagRECT
        public tagRECT rcContact;
    
        /// RECT->tagRECT
        public tagRECT rcContactRaw;
    
        /// UINT32->unsigned int
        public uint orientation;
    
        /// UINT32->unsigned int
        public uint pressure;
    }
    
    [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
    public struct Point {
    
        /// LONG->int
        public int x;
    
        /// LONG->int
        public int y;
    }
    
    [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
    public struct tagRECT {
    
        /// LONG->int
        public int left;
    
        /// LONG->int
        public int top;
    
        /// LONG->int
        public int right;
    
        /// LONG->int
        public int bottom;
    }
    
    [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
    public struct HWND__ {
    
        /// int
        public int unused;
    }
    
    public partial class NativeMethods {
    
        /// Return Type: BOOL->int
        ///maxCount: UINT32->unsigned int
        ///dwMode: DWORD->unsigned int
        [System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint="InitializeTouchInjection")]
        [return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
    public static extern  bool InitializeTouchInjection(uint maxCount, uint dwMode) ;
    
    
        /// Return Type: BOOL->int
        ///count: UINT32->unsigned int
        ///contacts: POINTER_TOUCH_INFO*
        [System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint="InjectTouchInput")]
        [return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
    public static extern  bool InjectTouchInput(uint count, ref tagPOINTER_TOUCH_INFO contacts) ;
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多