Skip to content

Instantly share code, notes, and snippets.

@wldevries
Last active April 30, 2023 20:56
Show Gist options
  • Save wldevries/d6e2d542fec4feafc114612c16536233 to your computer and use it in GitHub Desktop.
Save wldevries/d6e2d542fec4feafc114612c16536233 to your computer and use it in GitHub Desktop.
Disable touch and gesture feedback in Windows
using System;
using System.Runtime.InteropServices;
namespace SetTouchSettings
{
class Program
{
private static class NativeMethods
{
[DllImport("user32.dll", EntryPoint = "SystemParametersInfo", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SystemParametersInfoSet(uint uiAction, uint uiParam, UIntPtr pvParam, uint fWinIni);
[DllImport("user32.dll", EntryPoint = "SystemParametersInfo", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SystemParametersInfoGet(uint uiAction, uint uiParam, ref UIntPtr pvParam, uint fWinIni);
}
const uint SPIF_SENDCHANGE = 0x02;
const uint SPI_SETCONTACTVISUALIZATION = 0x2019;
const uint SPI_SETGESTUREVISUALIZATION = 0x201B;
const uint SPI_GETCONTACTVISUALIZATION = 0x2018;
const uint SPI_GETGESTUREVISUALIZATION = 0x201A;
const uint CONTACTVISUALIZATION_OFF = 0x0000;
const uint GESTUREVISUALIZATION_OFF = 0x0000;
static void Main(string[] args)
{
DisableTouchScreenFeedback();
Console.ReadKey();
}
public static void DisableTouchScreenFeedback()
{
PrintVis();
var cont = new UIntPtr(CONTACTVISUALIZATION_OFF);
if (!NativeMethods.SystemParametersInfoSet(SPI_SETCONTACTVISUALIZATION, 0, cont, SPIF_SENDCHANGE))
{
Console.WriteLine("set contact error " + Marshal.GetLastWin32Error());
}
var gest = new UIntPtr(GESTUREVISUALIZATION_OFF);
if (!NativeMethods.SystemParametersInfoSet(SPI_SETGESTUREVISUALIZATION, 0, gest, SPIF_SENDCHANGE))
{
Console.WriteLine("set gesture error " + Marshal.GetLastWin32Error());
}
PrintVis();
}
private static void PrintVis()
{
UIntPtr value = new UIntPtr();
NativeMethods.SystemParametersInfoGet(SPI_GETCONTACTVISUALIZATION, 0, ref value, SPIF_SENDCHANGE);
Console.WriteLine("Contact vis " + value.ToUInt32());
NativeMethods.SystemParametersInfoGet(SPI_GETGESTUREVISUALIZATION, 0, ref value, SPIF_SENDCHANGE);
Console.WriteLine("Gesture vis " + value.ToUInt32());
}
}
}
@luojunyuan
Copy link

man you make my world

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment