0

I'm trying to make a program that basically executes a mouse macro on other windows/apps in a given interval of time.

I've already managed create the timer, mapping and saving the 3 positions on screen that I need (using [DllImport("User32.Dll")] and GetCursorPos/SetCursorPos/mouse_event to do the left click) and even manage to do the mouse move on screen using LinearSmoothMove.

The problem is when I execute the function the mouse moves until it reaches the side of the window of this other app and then it "stops" (actually it looks like it's moving under the window). However, it works with other things like opening Notepad and going between the lines.

Sam
  • 7,252
  • 16
  • 46
  • 65
Duolk
  • 9
  • 2

1 Answers1

1

Please, see answer to similar question here. But before using ClickOnPointTool.ClickOnPoint() you should write the next code:

To find the certain process like this:

private IntPtr GetProcessMainWindowHandle(string mainWindowTitle)
{
    var processes = Process.GetProcesses();
    var foundProcess = processes.Single(p => mainWindowTitle.Equals(p.MainWindowTitle, StringComparison.CurrentCulture));
    // Also you can use method Process.GetProcessesByName(), it depends on your business logic
    return foundProcess.MainWindowHandle;
}

And to activate the found window using P/Invoke call of method SetForegroundWindow() with value of variable mainWindowHandle, recieved from GetProcessMainWindowHandle():

[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
Community
  • 1
  • 1
Didgeridoo
  • 1,222
  • 2
  • 14
  • 21
  • Also another answer to [this question](http://stackoverflow.com/questions/18849421/how-to-move-the-cursor-or-simulate-clicks-for-other-applications) may be useful for you. – Didgeridoo May 30 '15 at 11:40
  • Thank you, I manage to do some progress, but apparently in my case I'll need to take a step further... the left click is being ignored because the protection of an app (GameGuard) ... I imagine that the only way to get to work would be simulating a fake mouse drive that would realize the click when my application call... Any suggestions of where to start? Thank you in advance. – Duolk Jun 02 '15 at 00:25
  • May be [globalmousekeyhook library](https://github.com/gmamaladze/globalmousekeyhook) help you. If it can't help you, please try to see [SetWindowsHookEx() function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms644990(v=vs.85).aspx). You can find examples of use [here](http://www.codeproject.com/Articles/67091/Mouse-and-KeyBoard-Hooking-utility-with-VC) and [here](http://stackoverflow.com/questions/7761875/is-there-a-way-to-hook-mouse-events-for-a-specific-button-in-a-windows-form). – Didgeridoo Jun 03 '15 at 13:23