繁体   English   中英

wpf 按钮点击作为键盘 output

[英]wpf button click as keyboard output

我有两个按钮名称“A”,“B”想要单击它们等于单击键盘 A 和 B 按钮。 所以任何人都可以给我一个快速的方法来实现它。

谢谢

我会按照以下方式进行。 首先为 window 或其他父容器的按键事件添加事件处理程序:

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" KeyDown="Window_KeyDown" Width="525"> [...]

和事件处理程序:

private void Window_KeyDown(object sender, KeyEventArgs e)
{
        if (e.Key == Key.A)
            ButtonA.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
        else if (e.Key == Key.B)
            ButtonB.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM