Skip to content

Instantly share code, notes, and snippets.

@okathira
Last active January 21, 2022 08:16
Show Gist options
  • Save okathira/fee86bb21d07515c01236577d9a6dc43 to your computer and use it in GitHub Desktop.
Save okathira/fee86bb21d07515c01236577d9a6dc43 to your computer and use it in GitHub Desktop.
Open preference of individual app volume in Windows 10 (deprecated)
$OutputEncoding='utf-8'
Add-type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName Microsoft.VisualBasic
# original Send-Keys by @nimzo6689
# https://qiita.com/nimzo6689/items/488467dbe0c4e5645745
<#
.Synopsis
実行中の任意のプロセスにキーストロークを送る操作をします。
.DESCRIPTION
パラメータのキーストローク、プロセス名がそれぞれ未指定の場合、何も実行されません。
キーストロークのみが指定された場合は実行時のフォーカスへキーストロークを送り、
プロセス名のみが指定された場合はフォーカスのみが指定されたプロセスに変更します。
.EXAMPLE
Send-Keys -KeyStroke "test.%~" -ProcessName "LINE"
このコマンドは既に起動中のLINEアプリに対して"test."と入力し、
Altキーを押しながらEnterキーを押下する操作をしています。
#>
function Send-Keys
{
[CmdletBinding()]
[Alias("sdky")]
Param
(
# キーストローク
# アプリケーションに送りたいキーストローク内容を指定します。
# キーストロークの記述方法は下記のWebページを参照。
# https://msdn.microsoft.com/ja-jp/library/cc364423.aspx
[Parameter(Mandatory=$false,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[string]
$KeyStroke,
# プロセス名
# キーストロークを送りたいアプリケーションのプロセス名を指定します。
# 複数ある場合は、PIDが一番低いプロセスを対象とする。
# [Parameter(Mandatory=$false,
# ValueFromPipelineByPropertyName=$true)]
# [string]
# $ProcessName,
# プロセスタイトル
# キーストロークを送りたいアプリケーションのプロセスタイトルを指定します。
[Parameter(Mandatory=$false,
ValueFromPipelineByPropertyName=$true)]
[string]
$ProcessTitle,
# 待機時間
# コマンドを実行する前の待機時間をミリ秒単位で指定します。
[Parameter(Mandatory=$false,
ValueFromPipelineByPropertyName=$true)]
[int]
$Wait = 0
)
Process
{
Write-Verbose $ProcessTitle", KeyStroke = "$KeyStroke", Wait = "$Wait" ms."
Start-Sleep -Milliseconds $Wait
if ($ProcessTitle -ne $null)
{
[Microsoft.VisualBasic.Interaction]::AppActivate($ProcessTitle)
}
[System.Windows.Forms.SendKeys]::SendWait($KeyStroke)
}
}
Start-Process shell:AppsFolder\windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel
# send strokes
$title = "設定"
$wait = 1000
Send-Keys "{TAB}{ENTER}" -ProcessTitle $title -Wait $wait
Send-Keys "{TAB}{DOWN}{ENTER}" -ProcessTitle $title -Wait $wait
Send-Keys ("{TAB}"*11 + "{ENTER}") -ProcessTitle $title -Wait $wait
@okathira
Copy link
Author

D20mT6bU8AAGQsX

@okathira
Copy link
Author

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