How to disable all touch input at the application, window or control level?

Using C # for a wpf application, if Windows 7 touch control panel is enabled, by default, the user can "write" to InkCanvas with a finger. I want to disable this and enter only the input of the stylus.

I would like to know how to do this in more than one way, if possible: first InkCanvas off touching InkCanvas , secondly, turn it off for a specific window, and thirdly, turn it off for the entire application. The fourth bonus will know how to enable or disable the system as a whole.

I tried UnregisterTouchWindow and I tried to set Stylus.SetIsTouchFeedbackEnabled to false for InkCanvas , but none of them worked.

+4
source share
1 answer

Further digging helped me combine the following as a way to turn touch on and off throughout the system. If someone knows how to do this in any of the other three ways, I will still be grateful for these answers.

The main steps: check the current status of the registry, change it if necessary (and then update the system to recognize the change), and indicate the initial state for recovery if the program needs to exit.

Thanks to the posters in these two links for education.

 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); } } } 
+2
source

Source: https://habr.com/ru/post/1341342/


All Articles