问题描述
对于wpf应用程序使用c#,如果在控制面板中启用了Windows 7 touch,则默认情况下,用户可以用手指在InkCanvas
上进行书写".我想禁用它并仅强制手写笔输入.
Using c# for a wpf application, if in Windows 7 touch is enabled in the control panel, a user by default can 'write' on an InkCanvas
with a finger. I want to disable that and force stylus input only.
如果可能的话,我想知道如何通过多种方式进行操作:首先是通过禁用InkCanvas
的触摸,其次是通过禁用特定窗口的触摸,然后是通过禁用整个应用程序的触摸.奖金四分之一是知道如何在系统范围内打开或关闭触摸.
I'd like to know how to do it more than one way if possible: first by disabling touch on the InkCanvas
, second by disabling it for a particular window, and third by disabling it for the entire application. A bonus fourth would be knowing how to turn touch on or off system-wide.
我尝试了UnregisterTouchWindow
,并且尝试将Stylus.SetIsTouchFeedbackEnabled
的Stylus.SetIsTouchFeedbackEnabled
设置为false,但是都无效.
I have tried UnregisterTouchWindow
, and I have tried setting Stylus.SetIsTouchFeedbackEnabled
to false for the InkCanvas
, but neither has worked.
推荐答案
进一步的挖掘帮助我整理了以下内容,作为在整个系统范围内启用/禁用触摸的一种方法.如果有人知道如何以其他三种方式中的任何一种来完成此任务,我仍然会感激那些答案.
Further digging helped me put together the following as a way to toggle touch on/off system-wide. If anyone knows how to accomplish this in any of the other 3 ways, I'd still appreciate those answers.
基本步骤是检查当前注册表状态,必要时进行更改(然后刷新系统以识别更改),并记下要在程序退出时恢复的初始状态.
The basic steps are to check the current registry status, change it if necessary (and then refresh the system to recognize the change), and make note of the initial state to restore if needed on program exit.
感谢这些两个 链接.
public MainWindow(){
InitializeComponent();
RegistryKey regKey = Registry.CurrentUser;
regKey = regKey.OpenSubKey(@"Software\Microsoft\Wisp\Touch", true);
string currKey = regKey.GetValue("TouchGate").ToString();
if (currKey == "1")
{
regKey.SetValue("TouchGate", 0x00000000);
User32Utils.Notify_SettingChange();
UserConfig.TGate = "1";
}
regKey.Close();
...
}
public static class UserConfig {
public static string TGate { get; set; }
...
}
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e){
...
if (UserConfig.TGate == "1")
{
RegistryKey regKey = Registry.CurrentUser;
regKey = regKey.OpenSubKey(@"Software\Microsoft\Wisp\Touch", true);
regKey.SetValue("TouchGate", 0x00000001);
User32Utils.Notify_SettingChange();
regKey.Close();
}
}
//------------------User32Utils.cs
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace (...)
{
internal class User32Utils
{
#region USER32 Options
static IntPtr HWND_BROADCAST = new IntPtr(0xffffL);
static IntPtr WM_SETTINGCHANGE = new IntPtr(0x1a);
#endregion
#region STRUCT
enum SendMessageTimeoutFlags : uint
{
SMTO_NORMAL = 0x0000,
SMTO_BLOCK = 0x0001,
SMTO_ABORTIFHUNG = 0x2,
SMTO_NOTIMEOUTIFNOTHUNG = 0x0008
}
#endregion
#region Interop
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern IntPtr SendMessageTimeout(IntPtr hWnd,
uint Msg,
UIntPtr wParam,
UIntPtr lParam,
SendMessageTimeoutFlags fuFlags,
uint uTimeout,
out UIntPtr lpdwResult);
#endregion
internal static void Notify_SettingChange()
{
UIntPtr result;
SendMessageTimeout(HWND_BROADCAST, (uint)WM_SETTINGCHANGE,
UIntPtr.Zero, UIntPtr.Zero,
SendMessageTimeoutFlags.SMTO_NORMAL, 1000, out result);
}
}
}
这篇关于如何在应用程序,窗口或控件级别关闭所有触摸输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!