这是我的代码:
void tbHotkey_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key == Key.LeftShift || e.Key == Key.RightShift || e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl || e.Key == Key.LeftAlt || e.Key == Key.RightAlt || e.Key == Key.LWin || e.Key == Key.RWin)
{
return;
}
bool IsWinDown = e.KeyboardDevice.IsKeyDown(Key.LWin) | e.KeyboardDevice.IsKeyDown(Key.RWin);
bool IsCtrlDown = e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) | e.KeyboardDevice.IsKeyDown(Key.RightCtrl);
bool IsAltDown = e.KeyboardDevice.IsKeyDown(Key.LeftAlt) | e.KeyboardDevice.IsKeyDown(Key.RightAlt);
bool IsShiftDown = e.KeyboardDevice.IsKeyDown(Key.LeftShift) | e.KeyboardDevice.IsKeyDown(Key.RightShift);
if (IsWinDown | IsCtrlDown | IsAltDown | IsShiftDown)
{
(sender as TextBox).Text =
(IsWinDown ? "Windows + " : "") +
(IsCtrlDown ? "Control + " : "") +
(IsAltDown ? "Alt + " : "") +
(IsShiftDown ? "Shift + " : "") +
e.Key.ToString();
}
}
它保存了用户键入的热键,KeyEventArgs.Key.ToString()
但我需要保存它以便我可以SendKeys.Send()
轻松地将它传递给方法中的“keys”参数。
谁能建议我该怎么做?