Skip to content

Instantly share code, notes, and snippets.

@daanta-real
Created February 16, 2026 09:59
Show Gist options
  • Select an option

  • Save daanta-real/a7ff2a371752e6ccd3dddbbd93a92369 to your computer and use it in GitHub Desktop.

Select an option

Save daanta-real/a7ff2a371752e6ccd3dddbbd93a92369 to your computer and use it in GitHub Desktop.
Windows 11 Touchpad Toggler
# Touchpad Toggler
# 터치패드 토글하기 스크립트
Add-Type -AssemblyName UIAutomationClient
Add-Type -AssemblyName UIAutomationTypes
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class WindowMover {
[DllImport("user32.dll")]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
}
"@
Start-Process "ms-settings:devices-touchpad"
# 설정 창 핸들을 잡을 때까지 아주 짧게 대기 후 화면 밖으로 이동
$timeout = [System.Diagnostics.Stopwatch]::StartNew()
while ($timeout.Elapsed.TotalSeconds -lt 2) {
$proc = Get-Process "SystemSettings" -ErrorAction SilentlyContinue
if ($proc.MainWindowHandle -ne 0) {
# 좌표를 -2000, -2000으로 옮겨서 눈에 안 보이게 함
[WindowMover]::SetWindowPos($proc.MainWindowHandle, [IntPtr]::Zero, -2000, -2000, 0, 0, 0x0001)
break
}
Start-Sleep -Milliseconds 10
}
# 2. 요소 자동 감지 (발견 즉시 실행)
$condition = [Windows.Automation.AndCondition]::new(
[Windows.Automation.PropertyCondition]::new([Windows.Automation.AutomationElement]::ClassNameProperty, "ToggleSwitch"),
[Windows.Automation.PropertyCondition]::new([Windows.Automation.AutomationElement]::NameProperty, "터치 패드")
)
# 최대 5초간 0.1초 간격으로 체크 (발견 시 즉시 중단 및 진행)
$element = $null
$timeout = [System.Diagnostics.Stopwatch]::StartNew()
while ($timeout.Elapsed.TotalSeconds -lt 5) {
$element = [Windows.Automation.AutomationElement]::RootElement.FindFirst([Windows.Automation.TreeScope]::Descendants, $condition)
if ($element) { break }
Start-Sleep -Milliseconds 10
}
# 3. 조작 및 종료
if ($element) {
# 토글 패턴을 가져와 실행
$toggle = $null
if ($element.TryGetCurrentPattern([Windows.Automation.TogglePattern]::Pattern, [ref]$toggle)) {
$toggle.Toggle()
}
}
# 설정 창 즉시 닫기
Get-Process "SystemSettings" -ErrorAction SilentlyContinue | Stop-Process -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment