Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
910 views
in Technique[技术] by (71.8m points)

wpf - How to turn off all touch input at application, window or control level?

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.

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.

I have tried UnregisterTouchWindow, and I have tried setting Stylus.SetIsTouchFeedbackEnabled to false for the InkCanvas, but neither has worked.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

Thanks to the posters at these two links for the education.

public MainWindow(){

    InitializeComponent();

    RegistryKey regKey = Registry.CurrentUser;
    regKey = regKey.OpenSubKey(@"SoftwareMicrosoftWispTouch", 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(@"SoftwareMicrosoftWispTouch", 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);
        }
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...