简体   繁体   English

如何控制其他程序?

[英]How Can I control another programs?

my question is general for all languages, but I'm using only C, so, I would like to get answer in this one. 我的问题对于所有语言都是通用的,但是我只使用C语言,因此,我想在这本书中得到解答。

My question is, How Can I control the behavior of another applications that I didn't write? 我的问题是,如何控制未编写的其他应用程序的行为?

For example: 例如:

  • How Can I fill this entry box (in this site) using C? 如何使用C填写此站点中的输入框? Do I need to control the browser? 我需要控制浏览器吗? (I'm using firefox.) (我正在使用Firefox。)

  • Still in this example, How Can I open another tab in this browser using C? 仍在此示例中,如何使用C在此浏览器中打开另一个选项卡? (see, I want to control this (看,我想控制这个
    application such another one) 申请另一个)

  • How Can I embed a program im my one? 如何在我的程序中嵌入程序?

  • How Can I fill a database program using your gui, doing it by c? 我如何使用您的gui填充数据库程序,由c完成?

and so on... 等等...

Thanks a lot! 非常感谢!

There's no concrete or single answer to your (multiple) questions because every program varies. 您的(多个)问题没有具体或单个答案,因为每个程序都各不相同。 Short of the desired application having an API, you can resort to using low level Win32 commands to identify handles of processes and windows within those processes which you want to change/read. 如果缺少具有API的所需应用程序,则可以使用低级Win32命令来标识要更改/读取的进程中的进程和窗口的句柄。 It's by no means a straightforward or scalable process though. 但是,这绝不是一个简单或可扩展的过程。

您必须与该程序API进行交互。

Some programs are scriptable and publish APIs that allow other programs to send commands to them. 某些程序是可编写脚本的,并且发布了API,这些API允许其他程序向它们发送命令。 If your "target" app does something like this, then that will typically be your best bet. 如果您的“目标”应用程序执行了此类操作,那么通常这是您的最佳选择。

If the app doesn't have a C API, then you probably can't control it in C. That doesn't mean it's impossible, only that you might need a different language. 如果应用程序没有C API,则您可能无法用C对其进行控制。这并不意味着它不可能,只是您可能需要其他语言。 If your app is a Windows GUI app, you can use AutoIt to interact with the GUI programmatically. 如果您的应用程序是Windows GUI应用程序,则可以使用AutoIt与GUI进行编程交互。

Typically you use a program's application programming interface (API) to gain access to publicly available functions that let you accomplish tasks within that program. 通常,您使用程序的应用程序编程接口(API)获得对公共可用功能的访问,这些功能使您可以在该程序中完成任务。 However, not every application has an API that you can use. 但是,并非每个应用程序都具有您可以使用的API。

You should start by looking at the documentation of the application you're intending to take control of with your program and seeing if they have an API suitable for your needs. 您应该先查看要通过程序控制的应用程序文档,并查看它们是否具有适合您需求的API。

Most of the time application need API to work with each other. 大多数时候,应用程序需要API才能相互配合。 There is another way around to automatise actions done to applications (like an user would). 有另一种方法可以使对应用程序执行的操作自动化(就像用户一样)。 For example on Windows there is an "language" named AutoIt which can interact with your computer. 例如,在Windows上,有一个名为AutoIt的“语言”可以与您的计算机进行交互。

I'm not really sure if this is what your seeking but it can do almost all the thing you asked for. 我不确定这是否是您的追求,但是它几乎可以完成您要求的所有事情。

question is, How Can I control the behavior of another applications that I didn't write 问题是,如何控制未编写的其他应用程序的行为

Answer: that depends on the application and platform (linux, windows, mac, ...). 答:这取决于应用程序和平台(Linux,Windows,Mac等)。 It generally does not depend on your language of choice. 它通常不取决于您选择的语言。

As an example, quite a lot of gtk/ kde programs on linux can be partially controlled via the dbus messaging bus. 例如,可以通过dbus消息传递总线部分控制Linux上的许多gtk / kde程序。 Those apps are designed to be controlled in that way. 这些应用旨在通过这种方式进行控制。

I think firefox has a command line option to open a new website using an already running browser. 我认为firefox有一个命令行选项,可以使用已经运行的浏览器打开新网站。

Applescript or automator on a mac can be used to control some apps too, I believe. 我相信,Mac上的Applescript或automator也可以用于控制某些应用程序。

In short, make a separate question on what you want to do exactly , stating both platform and app you need to control. 简而言之,对您要精确执行的操作提出一个单独的问题,说明您需要控制的平台和应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 pipe 中启动多个程序? - How can I launch multiple programs in a pipe? WPF:如何在不将焦点从目标控件移开的情况下将键发送到另一个控件 - WPF : How can I sendkeys to another control without taking focus away from the target control 如何通过终端Linux向程序发出特定命令? - How can i give specific commands to programs via terminal Linux? 如何在ubuntu上使用Makefile编译C程序? - How can i compile C programs with Makefile on ubuntu? 如何编译使用不推荐使用的功能(例如gets())的C程序 - How can I compile C programs that use deprecated functions, such as gets() 在有和没有UNICODE支持的情况下,如何在我的程序中使用_stprintf? - How can I use _stprintf in my programs, with and without UNICODE support? 我可以将Thread Sanitizer用于OpenMP程序吗? - Can I use Thread Sanitizer for OpenMP programs? 如何在Linux内核(sys.c)中创建可以由常规程序访问的结构类型? - How can I create a struct type in the linux kernel (sys.c) that can be accessed by regular programs? 我该如何重写程序,这样我就不必调用`flex`而是仅调用`bison`和`cc`? - How can I rewrite the programs, so that I don't have to call `flex` but only call `bison` and `cc`? 如何使用Dev-C ++查看我的C程序的输出? - How can I see an the output of my C programs using Dev-C++?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM