Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 正在尝试创建WPF触摸屏键盘应用程序,Can';无法让WPF应用程序将密钥发送到另一个窗口?有什么建议吗?_C#_Wpf_Vb.net_Sendkeys_Multitouch Keyboard - Fatal编程技术网

C# 正在尝试创建WPF触摸屏键盘应用程序,Can';无法让WPF应用程序将密钥发送到另一个窗口?有什么建议吗?

C# 正在尝试创建WPF触摸屏键盘应用程序,Can';无法让WPF应用程序将密钥发送到另一个窗口?有什么建议吗?,c#,wpf,vb.net,sendkeys,multitouch-keyboard,C#,Wpf,Vb.net,Sendkeys,Multitouch Keyboard,我的触摸屏键盘是高度可定制的界面,有我需要的所有组件,除了发送键,任何人都会看到这个问题。最初,当我创建它时,我打算使用Forms.SendKeys.Send()但它是一个WPF应用程序。。。不行。对于初学者来说,VB.Net以其无限的智慧决定它不会处理默认表单消息。算了吧 或者,这是我真正的问题,我无法让WPF应用程序停止获得焦点。我希望它像windows触摸键盘一样工作,但是透明WPF中发生的每个动作都使该应用程序成为活动的。我希望事件仍然发生,但我需要活动窗口成为您希望键入的窗口,如记事本

我的触摸屏键盘是高度可定制的界面,有我需要的所有组件,除了发送键,任何人都会看到这个问题。最初,当我创建它时,我打算使用Forms.SendKeys.Send()但它是一个WPF应用程序。。。不行。对于初学者来说,VB.Net以其无限的智慧决定它不会处理默认表单消息。算了吧

或者,这是我真正的问题,我无法让WPF应用程序停止获得焦点。我希望它像windows触摸键盘一样工作,但是透明WPF中发生的每个动作都使该应用程序成为活动的。我希望事件仍然发生,但我需要活动窗口成为您希望键入的窗口,如记事本

关于我应该做什么,使我的WPF不可聚焦,并将键盘按钮发送到聚焦(或其他)窗口,有什么建议吗


另外,我正在Vb.Net中使用Visual Studio 2010中的WPF(我可以使用C代码!)

我想你会发现答案很有用

有很多可编译的方法来实现这一点,但我提出的解决方案是,上面的链接很简单,而且只有一个怪癖,老实说,可以解决。当拖动输入窗口时,它在移动完成之前不会提供反馈,但您可以通过处理一些非客户端消息来解决此问题。如果需要,我可以花一些时间查看解决方案,但首先确认此解决方案适合您

更新:上述方法如何应用于WPF表单的示例

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Runtime.InteropServices;

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

    const int WS_EX_NOACTIVATE = 0x08000000;
    const int GWL_EXSTYLE = -20;

    [DllImport("user32", SetLastError = true)]
    private extern static int GetWindowLong(IntPtr hwnd, int nIndex);

    [DllImport("user32", SetLastError = true)]
    private extern static int SetWindowLong(IntPtr hwnd, int nIndex, int dwNewValue);

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
      WindowInteropHelper wih = new WindowInteropHelper(this);
      int exstyle = GetWindowLong(wih.Handle, GWL_EXSTYLE);
      exstyle |= WS_EX_NOACTIVATE;
      SetWindowLong(wih.Handle, GWL_EXSTYLE, exstyle);
    }    
  }
}
使用系统;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Input;
使用System.Windows.Interop;
使用System.Runtime.InteropServices;
命名空间WpfApplication1
{
/// 
///Window1.xaml的交互逻辑
/// 
公共部分类Window1:Window
{
公共窗口1()
{
初始化组件();
}
常量int WS_EX_NOACTIVATE=0x08000000;
const int GWL_EXSTYLE=-20;
[DllImport(“user32”,SetLastError=true)]
私有外部静态int GetWindowLong(IntPtr hwnd,int nIndex);
[DllImport(“user32”,SetLastError=true)]
私有外部静态int SetWindowLong(IntPtr hwnd、int nIndex、int dwNewValue);
已加载私有无效窗口(对象发送器、路由目标)
{
WindowInteropHelper wih=新的WindowInteropHelper(此);
int exstyle=GetWindowLong(带句柄,GWL_exstyle);
exstyle |=WS_EX|u NOACTIVATE;
SetWindowLong(带手柄、GWL_EXSTYLE、EXSTYLE);
}    
}
}

这正是我要尝试的,它在Windows窗体环境中运行良好。事实上,我正在考虑返回windows窗体,但在WPF中,CreateParams覆盖不存在。因为其类型为System.Windows.Window,而不是System.Windows.Forms.Form。如果我不想使用新的表示层,我的生活会轻松得多。它比windows窗体更挑剔,但它是未来的。@Justin,您仍然可以将相同的原则应用于WPF。您只需要在创建后设置样式。我很快会发布一个快速的示例。我已经对它进行了调整,它工作得很好,它允许在使用动作时将焦点重新对准另一个窗口。谢谢,这解决了我的许多问题之一。现在我只需要让它将键盘键动作发送到另一个窗口。我试过SendKeys()不走运,我试过使用user32 dll来获取要发送的密钥,不走运。我用了这个例子:有什么想法吗?我会继续尝试,但是,我在这里画了一个空白。@Justin,当我实现我用SendKeys.SendWait测试的示例时,它对我有效,你尝试过这个吗?我会尝试send wait看看它有什么作用,现在我的窗口没有设置为焦点,我会看看它是否正常。