问题
It is often necessary to disable touch input when using a digitiser pen to avoid 'noise' from e.g. the hand resting on the screen. A programmatic solution exists to disable touch - but maintain pen - input in Windows 7, which changes the TouchGate registry value and broadcasts a system message; it seems that latter part fails in Windows 8.
Does anyone know how to update the code / an alternative solution for Windows 8 (note that my system does not allow me to disable touch input via the control panel GUI).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace Touch_Toggle
{
class Program
{
static void Main(string[] args)
{
Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.CurrentUser;
regKey = regKey.OpenSubKey(@"Software\Microsoft\Wisp\Touch", true);
string currKey = regKey.GetValue("TouchGate").ToString();
if (currKey == "1")
regKey.SetValue("TouchGate", 0x00000000);
else
regKey.SetValue("TouchGate", 0x00000001);
regKey.Close();
User32Utils.Notify_SettingChange();
}
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,
1,
out result
);
}
}
}
}
回答1:
After finding no answers elsewhere, an alternative is to toggle the appropriate device (if it is distinct from the pen) using a PowerShell script. Note that I have not tested this solution, since I no longer wish to use Windows 8.
You may need to enable PowerShell script execution on the local machine via group policy (Administrative Templates < Windows Components < Windows PowerShell).
First, download a copy of 'devcon.exe' (from Microsoft) for your machine. The following script then uses this command to achieve the desired effect assuming 'devcon.exe' is in the same directory.
$devid = "HID\WACOMVTHID&Col03"
$status = .\devcon status $devid | Select-String "running"
if($status -eq $null) {
write-host "Enabling touch"
.\devcon enable $devid
} else {
write-host "Disabling touch"
.\devcon disable $devid
}
The 'devid' parameter can be found as one of the 'Hardware Ids' in the device's properties.
来源:https://stackoverflow.com/questions/12255203/windows-8-touch-toggle