首页 > 解决方案 > C#如何判断用户是否左键单击?(来自表格外)

问题描述

好的,所以我正在尝试制作一个自动点击器,当您按住鼠标左键时它会开始点击。当用户按住鼠标左键但表单无法点击时,我得到它告诉我。然后我通过添加使表单可以点击

        [DllImport("user32.dll")]
        static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

        [DllImport("user32.dll", SetLastError = true)]
        static extern int GetWindowLong(IntPtr hWnd, int nIndex);

int initialStyle = GetWindowLong(this.Handle, -20);
            SetWindowLong(this.Handle, -20, initialStyle | 0x80000 | 0x20);
            this.TopMost = true;

但是一旦我让它可以点击,它并没有告诉我鼠标左键是否被按住。

所以基本上我制作了一个用户控制并设置点击速度和内容的主表单,然后我制作了第二个表单,它是屏幕的大小,并且是最顶部和透明的,所以如果你左键单击表单,它会读取我将鼠标按下功能设置为将布尔值设置为真或假,但是一旦我制作了可单击的表单,我猜它不会读取鼠标按下功能。

这是关于它如何检测是否按住鼠标左键的代码

        private void Form2_MouseDown(object sender, MouseEventArgs e)
        {
            if (MouseButtons == MouseButtons.Left)
            {
                mousedownheld = true;
            }
        }

        private void Form2_MouseUp(object sender, MouseEventArgs e)
        {
            mousedownheld = false;
            mousedownheld2 = true;
        }

标签: c#

解决方案


推荐阅读