.EXE窗口中的鼠标模拟

Mouse Simulation In .exe window

本文关键字:鼠标 模拟 窗口 EXE      更新时间:2023-10-16

我想制作鼠标宏。这既可以进行模拟的鼠标事件,也可以在屏幕上使用我的计算机自己的光标。

应通过输入IDE中的方法来创建宏。然后,这些方法应在某个.EXE的窗口上执行鼠标事件。通过使用坐标。

例如,这是我执行模拟或未模拟鼠标的方法的目标

psuedo代码:

//Following method left clicks with the offset (x, y) 
//from the windows top left corner. If the bool isSimulated 
//is set to true the click will be simulated else the computers 
//own mouse cursor will be moved and execute the mouse event.
LeftMouseClickOnWindow(x, y, isSimulated);

要进一步解决问题,模拟鼠标clicks 在窗口最小化或未关注时应起作用。

我想知道创建这种uti的最佳方法是什么。

user32.dll的功能是一种很好的方法吗?

在C 而不是C#?

中进行操作更容易

任何建议,来源,示例代码和评论都受到热烈赞赏!

C 和C#都很棒。Autohotkey可以完成这项工作,但我就像您一样 - 我喜欢写自己的东西。另一个选项是自动选择,您可以在C#项目中使用其dll ...但是您必须确保它已安装在每个系统上...不是我经常遇到的奢侈品。

这是可以玩的东西。希望它会让您前进...请注意,它是C#。在运行此代码之前,请确保您在鼠标处于位置的地方没有任何重要的打开...这将在对角线向右下方移动20次,并在每次移动时执行单击。您不希望这意外关闭您的东西。因此,在运行此之前,只需最小化所有内容即可。

using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace ConsoleApplication
{
    class Program
    {
        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
        private const int MOUSEEVENTF_LEFTDOWN = 0x02;
        private const int MOUSEEVENTF_LEFTUP = 0x04;
        //private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
        //private const int MOUSEEVENTF_RIGHTUP = 0x10;
        public void DoMouseStuff()
        {
            Cursor.Current = new Cursor(Cursor.Current.Handle);
            var point = new Point(Cursor.Position.X, Cursor.Position.Y);
            for (int i = 0; i < 20; i++, point.X += 10, point.Y += 10)
            {
                Cursor.Position = point;
                Program.mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, (uint)Cursor.Position.X, (uint)Cursor.Position.Y, 0, 0);
                System.Threading.Thread.Sleep(100);
            }
        }
        static void Main(string[] args)
        {
            var prog = new Program();
            prog.DoMouseStuff();
        }
    }
}

您需要为System.Windows.Forms&amp;设置引用System.Drawing,如果您还没有设置。我将其作为控制台应用程序,因此需要为我设置。当您注意到,我包括System.Threading.Thread.Sleep(100); ...这是这样您可以看到发生了什么。因此,我基本上正在放慢整个过程。它会移动,并且每次移动时都会单击(每100毫秒大约每100毫秒)。

熟悉Cursoruser32.dll

最后但并非最不重要的一点是,这是鼠标&amp;键盘模拟:http://msdn.microsoft.com/en-us/library/ms171548.aspx