char-slop/ai-dots

ai dotfiles

git clone https://git.t4t.associates/char-slop/ai-dots

Charlotte Somcomputer use for windowsdc2c12a

main
1.5 KiB34 linesraw
1$ErrorActionPreference = 'Stop'
2[Console]::InputEncoding = New-Object System.Text.UTF8Encoding($false)
3[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)
4
5Add-Type -Path (Join-Path $PSScriptRoot 'windows.cs') -ReferencedAssemblies System,System.Core,System.Drawing
6[PiDesktop]::Initialize()
7try {
8    while ($null -ne ($line = [Console]::ReadLine())) {
9        try {
10            $request = $line | ConvertFrom-Json
11            $response = @{}
12            switch ($request.action) {
13                'pointer' {
14                    [PiDesktop]::Pointer($request.x, $request.y, [string[]]$request.buttons)
15                }
16                'scroll' {
17                    $ticks = if ($null -eq $request.ticks) { 1 } else { $request.ticks }
18                    [PiDesktop]::Scroll($request.x, $request.y, $request.direction, $ticks, [string[]]$request.buttons)
19                }
20                'type' { [PiDesktop]::TypeText($request.text) }
21                'key' { [PiDesktop]::PressKey($request.key, [string[]]$request.modifiers) }
22                'new_browser_tab' { [PiDesktop]::OpenBrowser($request.url) }
23                'screenshot' { $response.png = [PiDesktop]::Screenshot() }
24                default { throw "Unsupported desktop action: $($request.action)" }
25            }
26            [Console]::WriteLine(($response | ConvertTo-Json -Compress))
27        } catch {
28            [Console]::WriteLine((@{ error = $_.Exception.GetBaseException().Message } | ConvertTo-Json -Compress))
29            break
30        }
31    }
32} finally {
33    [PiDesktop]::Release()
34}