WPF:使用TeamViewer且本地/远程输入语言不匹配时,不会触发键盘事件

时间:2018-09-06 17:20:33

标签: wpf keyboard teamviewer

我刚刚注意到最奇怪的事情,我希望有人能帮助我解决这个谜。

我使用TeamvViewer连接到我的生产机器并解决我编写的WPF应用程序的问题。我们的系统通常安装了几种键盘输入语言。我注意到,如果本地计算机上选择的输入语言与远程计算机上选择的输入语言不同,并且我输入了任何文本,那么远程计算机将把文本输入到具有焦点的任何控件中,但是...该控件的键盘事件不会触发(PreviewKeyDown,KeyDown,PreviewKeyUp,KeyUp)。

通过下面的WPF代码(通过TeamViewer运行)可以很容易地证明这一点。有人知道为什么会这样吗?

XAML:

<Window x:Class="TestWpfApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        PreviewKeyDown="MainWindow_OnPreviewKeyDown"
        KeyDown="MainWindow_OnKeyDown"
        PreviewKeyUp="MainWindow_OnPreviewKeyUp"
        KeyUp="MainWindow_OnKeyUp"
        Title="MainWindow" Height="350" Width="525">
    <StackPanel>
        <TextBlock
            x:Name="PreviewKeyDownLog"
        />
        <TextBlock
            x:Name="KeyDownLog"
        />
        <TextBlock
            x:Name="PreviewKeyUpLog"
        />
        <TextBlock
            x:Name="KeyUpLog"
        />
        <TextBox/>
    </StackPanel>
</Window>

后面的XAML代码:

using System;
using System.Printing;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Speedocs.Helpers;

namespace TestWpfApplication
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void MainWindow_OnKeyUp(object sender, KeyEventArgs e)
        {
            KeyUpLog.Text = "Key up " + Guid.NewGuid();
        }

        private void MainWindow_OnPreviewKeyDown(object sender, KeyEventArgs e)
        {
            PreviewKeyDownLog.Text = "Preview key down " + Guid.NewGuid();
        }

        private void MainWindow_OnKeyDown(object sender, KeyEventArgs e)
        {
            KeyDownLog.Text = "Key down " + Guid.NewGuid();
        }

        private void MainWindow_OnPreviewKeyUp(object sender, KeyEventArgs e)
        {
            PreviewKeyUpLog.Text = "Preview key up " + Guid.NewGuid();
        }
    }
}

0 个答案:

没有答案