Skip to content

Instantly share code, notes, and snippets.

@CannoHarito
Created November 12, 2022 10:40
Show Gist options
  • Save CannoHarito/c215044d8ebc684b961bba8397830426 to your computer and use it in GitHub Desktop.
Save CannoHarito/c215044d8ebc684b961bba8397830426 to your computer and use it in GitHub Desktop.
音声入力デバイスの"このデバイスを聴く"を切り替える 参考文献https://nyanshiba.hatenablog.com/entry/2017/08/21/221555
# https://nyanshiba.hatenablog.com/entry/2017/08/21/221555
param([int]$InputDevice = 3)
# Add-Type -AssemblyName System.Windows.Forms
$wshShell = New-Object -ComObject WScript.Shell
function Send-Keys {
param(
[Parameter(ValueFromPipeline = $true)][string]$key,
[int]$wait = 100
)
Process {
Start-Sleep -Milliseconds $wait
$wshShell.SendKeys($key)
# [Windows.Forms.SendKeys]::SendWait($key)
}
}
control mmsys.cpl
do {
Start-Sleep -Milliseconds 400
} until (
$wshShell.AppActivate("サウンド")
)
@"
^{TAB}
{DOWN $InputDevice}%P
^{TAB}
~
~
"@ -split "[\r\n]+" | Send-Keys
@CannoHarito
Copy link
Author

CannoHarito commented Nov 12, 2022

JScriptからの脱却を図りたかったが、wshShell.AppActivateの代わりがややこしいのでこれでいいかなって。
多バイト文字列が入るのでUTF-8(BOM付き)で保存しないとエラーでます。

$iwr=iwr -useb https://gist.githubusercontent.com/CannoHarito/c215044d8ebc684b961bba8397830426/raw/Switch-Lineinput.ps1
$iwr.content | Out-File -Encoding utf8 Switch-Lineinput.ps1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment