Simulate mouse click on a minimized window

自作多情 提交于 2019-12-25 03:55:27

问题


I am currently writing an application in C# that will recognize certain patterns on the screen and move to mouse to click on it. Currently, the application needs to have the focus and the mouse cursor moves, so the computer is unusable while the program is running. I would like to simulate a mouse click on a window but without actually moving the mouse on the screen. My goal would be to be able to simulate mouse click on a application that is minimized. Would that be easy to make in C#?


回答1:


You should read about using Windows API from .NET (PInvoke). Start with these:

http://msdn.microsoft.com/en-us/library/bb775985(v=vs.85).aspx

http://www.codeguru.com/forum/showthread.php?t=427934




回答2:


try this:

public const int SW_MAXIMIZE = 3;
private delegate bool EnumDesktopWindowsDelegate(IntPtr hWnd, int lParam);

[DllImport("user32.dll")]
static extern bool EnumDesktopWindows(IntPtr hDesktop, EnumDesktopWindowsDelegate lpfn, IntPtr lParam);
[DllImport("user32.dll", EntryPoint="FindWindow", SetLastError = true)]
public static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);
[DllImport("USER32.DLL")]
public static extern bool ShowWindow(IntPtr hWnd,int nCmdShow);


来源:https://stackoverflow.com/questions/7029453/simulate-mouse-click-on-a-minimized-window

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