我想从其他正在运行的应用程序中获取所选文本 [英] i want to get the selected text from other running application

查看:60
本文介绍了我想从其他正在运行的应用程序中获取所选文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个窗口形成一些为什么我想从其他正在运行的应用程序中使用全局挂钩键获取所选文本我知道如何使用挂钩键但我不知道如何获取所选文本

like网页浏览器或注意不好

解决方案

进入这样的事情显然是坏事。没有通用可靠的方法来做这样的伎俩;您可以为一个特定的应用程序执行此操作,但该方法不适用于其他应用程序。值得注意的是,如果您可以通过使用基于Windows消息传递机制的原始Windows API来访问某些控件并获取其文本,则它将不适用于基于Direct X并仅参与最高级别的Windows消息的WPF应用程序窗口,而控制UI元素的事件的内部生命对于Windows API仍然是完全不透明的。



使用全局Windows Hook,您当然可以完美地模拟输入设备,因此输入到任何类型的应用程序。它无法帮助您从这些应用程序中获取数据,例如所选文本或类似内容。



我无法看到真正合理的理由来做这些事情。这不是真正的编程工作。 软件工程是通过编写代码来完成的,而不是通过黑客攻击其他应用程序。如果你愿意,可以称之为集成,但对于不是专门为集成设计的应用程序,这就是黑客行为。如果你考虑一下 - 相当适得其反的活动,浪费时间。







以下是这样的事情:之前,你没有提到你只是想在系统键盘中选择文本。感谢您在下面的评论中做出的澄清。



这当然是非常可能的,而且实际上很容易。您所需要的只是使用原始Windows API SendInput

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



使用.NET,您需要使用P / Invoke来执行此操作,但这已经完成了您。在这里:

http://www.pinvoke.net/default.aspx/user32。 sendinput [ ^ ]。



你可以简单地模拟按下Ctrl + A(全选)Ctrl + C或Ctrl + Insert,或任何你需要的东西。



(记录:对我来说,它仍然是一个黑客,即使它很容易。这不是真正的软件工程的完成方式。)



-SA


im creating a windows forms some why i want to get selected text from other running applications using global hook keys i know how to use hook keys but i dont know how to get the selected text
like web browser or note bad

解决方案

Going in for such things is apparently the bad business. There is no an universal reliable way of doing such tricks; you can do it for one specific application, but that method won't work for others. Notably, if you can access some control and get its text by using raw Windows API based on Windows messaging mechanism, it won't work for WPF applications, which are based on Direct X and participate in windows message pumping only on the very top level of the window, while internal life of events controlling UI elements remains totally non-transparent to Windows API.

With the global Windows Hook, you of course can perfectly simulate input devices and hence input to any kinds of applications. It cannot help you to get data from those applications, such as selected text or anything like that.

And I cannot see truly legitimate reasons to do such things. This is not how real programming work. Software engineering is done by writing code, not by hacking other applications. If you want, call it "integration", but for the applications not specially designed for "integration" this is hacking. If you think about it — quite counter-productive activity, waste of time.

[EDIT]

Here is the thing: before, you did not mention that you merely wanted to get selected text in the system keyboard. Thank you for clarification in your comment below.

This is of course quite possible and actually easy enough. All you need is to use the raw Windows API SendInput:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^].

With .NET, you need to use P/Invoke to do it, but this is already done for you. Here:
http://www.pinvoke.net/default.aspx/user32.sendinput[^].

You can simply simulate the press to Ctrl+A (select all) Ctrl+C or Ctrl+Insert, or anything you need to get.

(For a record: to me, it will still remains a hack, even though it is very easy. This is not how real software engineering is done.)

—SA


这篇关于我想从其他正在运行的应用程序中获取所选文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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