Is it possible to programmatically click button of another app in Linux?

落花浮王杯 提交于 2019-12-11 07:18:13

问题


Is it possible to send an event to a particular widget (say a button) in Linux (X window system)

I am looking for an equivalent to the following code for Linux (using Xlib)

#include <windows.h>
int main()
{
  HWND WindowHandle;
  HWND ButtonHandle;

  WindowHandle = FindWindow(NULL, "File Download");
  ButtonHandle = FindWindowEx(WindowHandle, 0, "Button", "&Open");
  SendMessage (ButtonHandle, BM_CLICK, 0 , 0);

 return 0;
}

I guess that FindWindow can be simulated by XFetchName, but I have no idea how to find a particular widget's ID by name (FindWindowEx) in the case where I only know the widget "name" (i.e. caption in the case of a button).

Can I do that?


回答1:


Maybe, using the XTest extension:

http://www.x.org/releases/X11R7.5/doc/Xext/xtestlib.pdf

However, there is no portable way to determine what is and isn't a widget on the screen, as some GUI toolkits render everything as separate X objects, while others do their own compositing first.



来源:https://stackoverflow.com/questions/6893014/is-it-possible-to-programmatically-click-button-of-another-app-in-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!