From 94cd04ef62586e975b03501ffec18a2d2f9087d2 Mon Sep 17 00:00:00 2001 From: zlei9 Date: Sun, 29 Mar 2026 14:37:38 +0800 Subject: [PATCH] Initial commit with translated description --- SKILL.md | 56 +++++++++++++++++++++++++++++++++++++ _meta.json | 6 ++++ keyboard_control.ps1.txt | 13 +++++++++ mouse_control.ps1.txt | 60 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 SKILL.md create mode 100644 _meta.json create mode 100644 keyboard_control.ps1.txt create mode 100644 mouse_control.ps1.txt diff --git a/SKILL.md b/SKILL.md new file mode 100644 index 0000000..be5a436 --- /dev/null +++ b/SKILL.md @@ -0,0 +1,56 @@ +--- +name: windows-ui-automation +description: "使用PowerShell自动化Windows GUI交互。" +--- + +# Windows UI Automation + +Control the Windows desktop environment programmatically. + +## Core Capabilities + +- **Mouse**: Move, click (left/right/double), drag. +- **Keyboard**: Send text, press special keys (Enter, Tab, Alt, etc.). +- **Windows**: Find, focus, minimize/maximize, and screenshot windows. + +## Usage Guide + +### Mouse Control + +Use the provided PowerShell script `mouse_control.ps1.txt`: + +```powershell +# Move to X, Y +powershell -File skills/windows-ui-automation/mouse_control.ps1.txt -Action move -X 500 -Y 500 + +# Click at current position +powershell -File skills/windows-ui-automation/mouse_control.ps1.txt -Action click + +# Right click +powershell -File skills/windows-ui-automation/mouse_control.ps1.txt -Action rightclick +``` + +### Keyboard Control + +Use `keyboard_control.ps1.txt`: + +```powershell +# Type text +powershell -File skills/windows-ui-automation/keyboard_control.ps1.txt -Text "Hello World" + +# Press Enter +powershell -File skills/windows-ui-automation/keyboard_control.ps1.txt -Key "{ENTER}" +``` + +### Window Management + +To focus a window by title: +```powershell +$wshell = New-Object -ComObject WScript.Shell; $wshell.AppActivate("Notepad") +``` + +## Best Practices + +1. **Safety**: Always move the mouse slowly or include delays between actions. +2. **Verification**: Take a screenshot before and after complex UI actions to verify state. +3. **Coordinates**: Remember that coordinates (0,0) are at the top-left of the primary monitor. diff --git a/_meta.json b/_meta.json new file mode 100644 index 0000000..42f3b62 --- /dev/null +++ b/_meta.json @@ -0,0 +1,6 @@ +{ + "ownerId": "kn76wjjc3n518fh6het03rr7wx80yfjy", + "slug": "windows-ui-automation", + "version": "1.0.0", + "publishedAt": 1770809270308 +} \ No newline at end of file diff --git a/keyboard_control.ps1.txt b/keyboard_control.ps1.txt new file mode 100644 index 0000000..4c5e34a --- /dev/null +++ b/keyboard_control.ps1.txt @@ -0,0 +1,13 @@ +param ( + [string]$Text, + [string]$Key +) + +Add-Type -AssemblyName System.Windows.Forms + +if ($Text) { + [System.Windows.Forms.SendKeys]::SendWait($Text) +} +if ($Key) { + [System.Windows.Forms.SendKeys]::SendWait($Key) +} diff --git a/mouse_control.ps1.txt b/mouse_control.ps1.txt new file mode 100644 index 0000000..710467c --- /dev/null +++ b/mouse_control.ps1.txt @@ -0,0 +1,60 @@ +param ( + [Parameter(Mandatory=$true)] + [ValidateSet("move", "click", "rightclick", "doubleclick")] + [string]$Action, + + [int]$X = 0, + [int]$Y = 0 +) + +Add-Type -AssemblyName System.Windows.Forms + +switch ($Action) { + "move" { + [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($X, $Y) + } + "click" { + $source = @" +using System; +using System.Runtime.InteropServices; +public class Mouse { + [DllImport("user32.dll")] + public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo); +} +"@ + Add-Type -TypeDefinition $source -ErrorAction SilentlyContinue + [Mouse]::mouse_event(0x02, 0, 0, 0, 0) # Left Down + Start-Sleep -Milliseconds 50 + [Mouse]::mouse_event(0x04, 0, 0, 0, 0) # Left Up + } + "rightclick" { + $source = @" +using System; +using System.Runtime.InteropServices; +public class MouseRight { + [DllImport("user32.dll")] + public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo); +} +"@ + Add-Type -TypeDefinition $source -ErrorAction SilentlyContinue + [MouseRight]::mouse_event(0x08, 0, 0, 0, 0) # Right Down + Start-Sleep -Milliseconds 50 + [MouseRight]::mouse_event(0x10, 0, 0, 0, 0) # Right Up + } + "doubleclick" { + $source = @" +using System; +using System.Runtime.InteropServices; +public class MouseDouble { + [DllImport("user32.dll")] + public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo); +} +"@ + Add-Type -TypeDefinition $source -ErrorAction SilentlyContinue + [MouseDouble]::mouse_event(0x02, 0, 0, 0, 0) + [MouseDouble]::mouse_event(0x04, 0, 0, 0, 0) + Start-Sleep -Milliseconds 50 + [MouseDouble]::mouse_event(0x02, 0, 0, 0, 0) + [MouseDouble]::mouse_event(0x04, 0, 0, 0, 0) + } +}