$ErrorActionPreference = 'Stop'
$taskName = 'TibiaPilotNG-TouchKeyboard'
$executable = Join-Path `
    ${env:CommonProgramFiles} `
    'microsoft shared\ink\TabTip.exe'

Unregister-ScheduledTask `
    -TaskName $taskName `
    -Confirm:$false `
    -ErrorAction SilentlyContinue

$action = New-ScheduledTaskAction -Execute $executable
$principal = New-ScheduledTaskPrincipal `
    -UserId $env:USERNAME `
    -LogonType Interactive `
    -RunLevel Limited

Register-ScheduledTask `
    -TaskName $taskName `
    -Action $action `
    -Principal $principal | Out-Null
Start-ScheduledTask -TaskName $taskName
Start-Sleep -Seconds 3

Get-Process TabTip, TextInputHost -ErrorAction SilentlyContinue |
    Select-Object ProcessName, Id, SessionId, MainWindowTitle, MainWindowHandle |
    ConvertTo-Json -Compress
