将密钥发送到单独应用程序的组合框 [英] Sending Keys to combobox of a separate application

查看:77
本文介绍了将密钥发送到单独应用程序的组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向外部应用程序发送 ^ c ,在使用Spy ++找到目标的窗口/类名后,我有这个:

I''m sending "^c" to an external application, after finding window/class name of my target with Spy++, I have this :

[DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
            public static extern IntPtr FindWindow(string lpClassName,
                string lpWindowName);

            [DllImport("USER32.DLL")]
            public static extern bool SetForegroundWindow(IntPtr hWnd);

    private void button1_Click(object sender, EventArgs e)
            {
                IntPtr newzieHandle= FindWindow("Afx:00400000:0", "Newzie");

                if (newzieHandle== IntPtr.Zero)
                {
                    MessageBox.Show("Unable to detect Newzie");
                    return;
                }
                SetForegroundWindow(newzieHandle);
                SendKeys.SendWait("^c");
            }



问题是,extrenal应用程序已经有一个默认的快捷键ctrl + c,无法禁用!那么有没有办法将密钥只发送到一个comboBox而不是整个应用程序?

我的目标应用程序线程的Spy ++图像 [ ^ ]

外部应用ScreenShot [ ^ ]。

更新我试过了# SendInput wrapper [ ^ ]并始终存在同样的问题。


The problem is that the extrenal application already haves a default shortcut "ctrl+c" that can''t be disabled! So is there a way to send the keys only to a comboBox and not to the whole application?
Image of Spy++ for my target application thread[^]
External app ScreenShot[^].
Update I tried a c# SendInput wrapper[^] and always have the same problem.

推荐答案

这是一种非常不可靠的技术。如果你要模拟输入,你应该更好地使用真正的低级方法 SendInput

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v = vs.85%29.aspx [ ^ ]。



这是如何在.NET中执行的:http://www.pinvoke.net/default.aspx/user32.sendinput [ ^ ]。



但是,我应该警告你:使用输入的模拟(任何类型,从蹩脚的.NET SendKeys 开始到强大的 SendInput )常规UI开发将是一个巨大的滥用。通常的.NET FCL将是相当充分和兼容的方式。输入的模拟应仅用于非常特殊的实用程序。示例包括播放键盘/鼠标宏,UI测试实用程序,虚拟键盘等等。



-SA
This is a very unreliable technique. If you wan to simulate input, you should better use really low-level method SendInput:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^].

This is how to do it in .NET: http://www.pinvoke.net/default.aspx/user32.sendinput[^].

However, I should warn you: using simulation of the input (of any kind, starting from the lame .NET SendKeys to powerful SendInput) for "regular" UI development would be a huge abuse. The usual .NET FCL would be quite sufficient and compatible way. Simulation of input should be used only in very special utilities. Examples include playing of keyboard/mouse macro, UI testing utilities, virtual keyboard, something like that.

—SA


这篇关于将密钥发送到单独应用程序的组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆