Created
November 12, 2022 10:40
-
-
Save CannoHarito/c215044d8ebc684b961bba8397830426 to your computer and use it in GitHub Desktop.
音声入力デバイスの"このデバイスを聴く"を切り替える 参考文献https://nyanshiba.hatenablog.com/entry/2017/08/21/221555
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
JScriptからの脱却を図りたかったが、wshShell.AppActivateの代わりがややこしいのでこれでいいかなって。
多バイト文字列が入るのでUTF-8(BOM付き)で保存しないとエラーでます。