Я не знаю, почему вы получаете системный звуковой сигнал при нажатии горячей клавиши, но это может быть связано с тем, как вы добавляете KeyEventHandler в форму.
Использование $form1.Add_KeyDown({..})
не доставляет мне никаких проблем:
$form1.Add_KeyDown({
# create a small array to capture the modifier keys used
$modifiers = @()
if ($_.Shift) { $modifiers += "Shift" }
if ($_.Alt) { $modifiers += "Alt" }
if ($_.Control) { $modifiers += "Control" }
# using that array, build part of the output text
$modkeys = ''
if ($modifiers.Count) {
$modkeys = '{0} ' -f ($modifiers -join ' + ')
}
# instead of building up a string 'Shift + Control + Alt', like above, you can also use
# the $_.Modifiers property and replace the commas by a plus sign like this:
# $modkeys = $_.Modifiers -replace ', ', ' + '
# these are the keys you want to react upon as example
# here all keys pressed simply do the same thing, namely display what was pressed,
# so we can shorten the code to simply test if any of the keys in the
# array correspond with the key the user pressed.
if ('Q','A','F1','Escape','NumLock' -contains $_.KeyCode) {
# we create the output string by making use of the '-f' Format operator in POwershell.
# you can read more about that here for instance:
# https://social.technet.microsoft.com/wiki/contents/articles/7855.powershell-using-the-f-format-operator.aspx
Write-Host ('{0}{1} pressed' -f $modkeys, $_.KeyCode)
# The same could have been done with something like:
# Write-Host ($modkeys + ' ' + $_.KeyCode + ' pressed')
# or
# Write-Host "$modkeys $($_.KeyCode) pressed"
}
})