如何使用其他程序单击某些程序上的按钮 [英] How to click buttons on some programs using another program

查看:83
本文介绍了如何使用其他程序单击某些程序上的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个控制台应用程序,在启动后单击一下。以下是代码:



i've created a console application that does one click after it started. Here is the code:

class Program
{
    static void Main(string[] args)
    {

        Thread.Sleep(5000);
        mouse_event((uint)MouseEventFlags.LEFTDOWN, 100, 100, 0, 0);
        Thread.Sleep(300);
        mouse_event((uint)MouseEventFlags.LEFTUP, 100, 100, 0, 0);
    }

    [Flags]
    public enum MouseEventFlags
    {
        LEFTDOWN = 0x00000002,
        LEFTUP = 0x00000004,
        MIDDLEDOWN = 0x00000020,
        MIDDLEUP = 0x00000040,
        MOVE = 0x00000001,
        ABSOLUTE = 0x00008000,
        RIGHTDOWN = 0x00000008,
        RIGHTUP = 0x00000010
    }

    [DllImport("user32.dll")]
    private static extern void mouse_event(
        long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);


}





此示例适用于记事本,但是在其他应用程序中它什么都不做它不起作用的应用程序是下面提到的点击器。



我需要做些什么才能使其在其他应用程序中工作?



这是我在网上找到的点击器 Clicker (拿第一个) ,这个可以点击我的程序没有点击的其他应用程序。你可以在这个窗口点击器中运行我的代码并且它不起作用,如果我的点击者可以点击这个点击器中的开始/停止,那将是很好的。



祝你好运!



This sample works in notepad, for example, but in other application it does nothing. An application in which it doesn't work is the clicker mentioned below.

what do i have to do to make it work in other applications?

Here is a clicker i found online Clicker(take the first one), and this one can click on another applications that my program doesn't click. You can run my code in this window clicker and it doesn't work, it would be great if my clicker can click start/stop in this clicker.

Best regards!

推荐答案

由于 mouse_event 已过时,最好使用Windows API SendInput

https:// msdn .microsoft.com / zh-CN / library / windows / desktop / ms646310%28v = vs.85%29.aspx

这是P / Invoke: http://www.pinvoke.net/default.aspx/user32.sendinput



由于这是一个非常低级的输入模拟,它与真正的硬件鼠标或键盘具有相同的效果,因此它非常可靠。由于这个低级别,应用程序是什么并不重要;这与通过真正的鼠标点击相同。我从来没有遇到任何问题。唯一的问题是为什么?



-SA
As mouse_event is obsolete, it's better to use Windows API SendInput:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx,
and this is P/Invoke for it: http://www.pinvoke.net/default.aspx/user32.sendinput.

As this is a very low-level input simulation, it has the same effect as real hardware mouse or keyboard, so it's very reliable. Because of this low level, it does not matter what are the application; this is the same as clicking by a real mouse. I never faced any problems with it. The only question would be "why"?

—SA


这篇关于如何使用其他程序单击某些程序上的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆