c# WPF 를 이용한 어플리케이션을 만들 때 태블릿 스타일러스 입력을 비활성화 하기 위한 소스다.
해당 소스는 마이크로소프트에 기재되어있는 소스로 주석을 한국어로 바뀐 후
일부 null 경고를 수정한 내용이다.
Disable the RealTimeStylus - WPF .NET Framework
Learn how to disable the built-in stylus support in a Windows Presentation Foundation (WPF) application.
learn.microsoft.com
/// <summary>
/// WFP 리플렉션을 사용하여 기본 태블릿 플랫폼 지원을 제거
/// https://learn.microsoft.com/en-us/dotnet/desktop/wpf/advanced/disable-the-realtimestylus-for-wpf-applications?view=netframeworkdesktop-4.8
/// </summary>
public static void DisableWPFTabletSupport()
{
try
{
// 시스템과 연결된 TabletDeviceCollection 을 가져온다.
// TabletDeviceCollection : 태블릿 디바이스의 디지타이저 디바이스를 나타내는 TabletDevice 개체
TabletDeviceCollection devices = System.Windows.Input.Tablet.TabletDevices;
// TabletDeviceCollection.Count : 컬렉션에 있는 TabletDevice 개체의 수
// 현재 윈도우에 활성화된 테블릿 디바이스가 존재할 경우.
if (devices.Count > 0)
{
// WPF의 모든 입력 시스템 조정
Type inputManagerType = typeof(System.Windows.Input.InputManager);
// 기본값이 있는 매개 변수를 사용하여 메서드를 호출
// InputManager.Current 인스턴스에서 StylusLogic 메서드를 호출
object? stylusLogic = inputManagerType.InvokeMember("StylusLogic",
BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
null, InputManager.Current, null);
if (stylusLogic is not null)
{
// StylusLogic 호출에서 반환된 StylusLogic 유형을 가져온다.
Type stylusLogicType = stylusLogic.GetType();
// 모든 장비가 제거될 때까지 반복한다.
while (devices.Count > 0)
{
//장치 컬렉션에서 첫 번째 태블릿 장치 제거 .
stylusLogicType.InvokeMember("OnTabletRemoved",
BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic,
null, stylusLogic, new object[] { (uint)0 });
}
}
}
}
catch (Exception ex)
{
}
}
'c# > helper' 카테고리의 다른 글
| c# ApplicationManifest 관리자 권한 설정 (0) | 2024.04.22 |
|---|---|
| c# ApplicationHighDpiMode 고해상도에서 선명하게 (0) | 2024.04.22 |
| c# 공인 ip 가져오기 / c# public ip 가져오기 (0) | 2024.04.02 |
| c# 로컬 ip 가져오기 / c# local ip 가져오기 (0) | 2024.04.02 |
| c# 왼쪽부터 문자열 자르기 (0) | 2024.04.02 |