PowerShell

# 1. 出力の文字化け対策
$OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8

Add-Type -AssemblyName Microsoft.VisualBasic
$wsh = New-Object -ComObject WScript.Shell

$endTime = "23:00"

Write-Host "--- Monitoring Started (Target: $endTime) ---"

while($true) {
    if ((Get-Date -Format "HH:mm") -ge $endTime) {
        Write-Host "Time reached. Exiting..."
        break
    }

    # 【重要】日本語を直接書かず、ワイルドカードで判定 (文字化け対策)
    # 「アイドル」という文字が含まれるウィンドウを探す
    $target = Get-Process | Where-Object { $_.MainWindowTitle -like "*アイドル*" } -ErrorAction SilentlyContinue
    
    if ($target) {
        $now = Get-Date -Format "HH:mm:ss"
        Write-Host "$now : Dialog detected. Sending Enter..."
        try {
            [Microsoft.VisualBasic.Interaction]::AppActivate($target.Id)
            Start-Sleep -Milliseconds 500
            $wsh.SendKeys('~') # Enterキー
        } catch {
            # 既に閉じている場合は無視
        }
    }

    # アイドル防止 (ScrollLock)
    $wsh.SendKeys('{SCROLLLOCK}')
    
    # 10秒待機
    Start-Sleep -Seconds 10
}

コメントを書く


Warning: Undefined variable $user_ID in /home/r6519429/public_html/tamura.jp/wp-content/themes/tamura_thema1/comments.php on line 156