Hello guys. I need help. I'm doing an auto click with left mouse, but I need it to click only on a specific window and it can be minimized and continue to click while I can do other things on the pc. How to navigate the web etc. This code works the wrong way. It clicks and I can move the mouse in the meantime. But, I can not use the left mouse button and move windows or even minimize the window in which the mouse was programmed to click because it stops clicking. can you help me? Thank you.
What I have tried:
<pre>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace AUTOCLIQUEMOUSEHK
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public enum WMessages : int
{
WM_LBUTTONDOWN = 0x201,
WM_LBUTTONUP = 0x202,
WM_LBUTTONDBLCLK= 0x203,
WM_RBUTTONDOWN= 0x204,
WM_RBUTTONUP = 0x205,
WM_RBUTTONDBLCLK = 0x206,
}
[DllImport("user32.dll")]
static extern IntPtr WindowFromPoint(int xPoint, int yPoint);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string ClassName, IntPtr WindowTitle);
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(String sClassName, String sAppName);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImport("user32.dll", SetLastError = true)]
static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
[DllImport("user32.dll")]
public static extern int SetActiveWindow(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern int SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern int GetWindowtext(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
public IntPtr findme()
{
return this.Handle;
}
private int MAKELPARAM(int p, int p_2)
{
return ((p_2 << 16) | (p & 0xFFFF));
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
}
private void button1_MouseMove(object sender, MouseEventArgs e)
{
this.Text = "X:" + Cursor.Position.X + "Y:" + Cursor.Position.Y;
}
private void timer1_Tick(object sender, EventArgs e)
{
IntPtr myHandle = findme();
Point pt = new Point(312, 324);
IntPtr handle = WindowFromPoint(pt.X, pt.Y);
PostMessage(handle, (uint)WMessages.WM_LBUTTONDOWN, 0, MAKELPARAM(pt.X, pt.Y));
PostMessage(handle, (uint)WMessages.WM_LBUTTONUP, 0, MAKELPARAM(pt.X, pt.Y));
SetForegroundWindow(myHandle);
}
}
}