wpf按钮点击作为键盘输出
答
我会这样做。首先添加事件处理程序窗口中的按键事件或其他一些父容器:
<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));
}
+0
谢谢我已经尝试过。但它不能工作。我想单击按钮名称'a',然后在doc文件或文本文件中显示'a'。 – Jessesiu 2012-04-07 15:01:48
如。窗口中的两个按钮按钮“a”和按钮“b”。我打开一个文本文件。并点击按钮'a',文字也显示出来。像虚拟键盘只有两个键a和b。 – Jessesiu 2012-04-07 15:06:18