读书人

模拟鼠标点击有关问题 C

发布时间: 2012-03-19 22:03:05 作者: rapoo

模拟鼠标点击问题 C#
我想做个 C#程序
程序运行时
自动 点击某网页的 固定坐标

50分求详细代码

[解决办法]
mouse_event
更方法的是使用WebBrowser控件

[解决办法]
up
[解决办法]
使用WebBrowser控件,在里面容易搞点
[解决办法]

C# code
[DllImport("user32.dll")]        private static extern void mouse_event        (        UInt32 dwFlags, // motion and click options        UInt32 dx, // horizontal position or change        UInt32 dy, // vertical position or change        UInt32 dwData, // wheel movement        IntPtr dwExtraInfo // application-defined information        );private const UInt32 MOUSEEVENTF_LEFTDOWN = 0x0002;        private const UInt32 MOUSEEVENTF_LEFTUP = 0x0004;        public void Click()        {            m_Browser.Visible = true;                        Point pp = new Point(CurrentTask.X, CurrentTask.Y);            Point screenPoint = m_MainForm.PointToScreen(pp);            screenPoint.X += m_Browser.Left;            screenPoint.Y += m_Browser.Top;            Cursor.Position = screenPoint;            mouse_event(MOUSEEVENTF_LEFTDOWN, (UInt32)pp.X, (UInt32)pp.Y, 0, new IntPtr());            for (int i = 0; i < 19; i++)            {                Thread.Sleep(20);                Application.DoEvents();            }            mouse_event(MOUSEEVENTF_LEFTUP, (UInt32)pp.X, (UInt32)pp.Y, 0, new IntPtr());            m_Browser.Visible = false;            m_State = ClickerState.Clicked;            m_CurrentTask = null;                        Thread.Sleep(100);                        //The element the browser clicked is not a link            if(m_State != ClickerState.Navigating)            {                m_State = ClickerState.WaitingTask;                Navigate(m_Manager.GetTask());            }        }
[解决办法]
探讨
m_Browser是什么啊 在哪定义的
m_State 是什么 在哪定义的
m_CurrentTask 是什么 在哪定义
m_Manager 是什么 在哪定义


[解决办法]
最好是在WebBrowser中实现,比你模拟鼠标点击强的多!
[解决办法]
探讨
哦~~
那 我怎么接受网页呢

我想实现在网页中电击一下

大侠多费费心  我初学

[解决办法]
只是刷票吗?
[解决办法]
当运行 Windows 窗体时,它将创建新窗体,然后该窗体等待处理事件。该窗体在每次处理事件时,均将处理与该事件关联的所有代码。所有其他事件在队列中等待。在代码处理事件时,应用程序并不响应。例如,当将另一窗口拖到该窗口前面时,该窗口不重新绘制。

如果在代码中调用 DoEvents,则您的应用程序可以处理其他事件。例如,如果您有向 ListBox 添加数据的窗体,并将 DoEvents 添加到代码中,那么当将另一窗口拖到您的窗体上时,该窗体将重新绘制。如果从代码中移除 DoEvents,那么在按钮的单击事件处理程序执行结束以前,您的窗体不会重新绘制。

与 Visual Basic 6.0 不同,DoEvents 方法不调用 Thread.Sleep 方法。

通常,您在循环中使用该方法来处理消息。

[解决办法]
不知道你点的啥,如果是按钮的话,在WebBrowser中要比你模拟按键方便的多!
[解决办法]
探讨
16楼的大哥
这段话我看过了。。
可是我不懂啊

我用Application.DoEvents();


可是并没有出现新窗体
能不能在详细点

[解决办法]
1.用Hook捕捉到鼠标点击
2.用GetCursorPos获鼠标点击时的坐标
3.用SetCursorPos设置鼠标的坐标
4.用mouse_event模拟鼠标点击
------解决方案--------------------


传说中有个地方叫msdn,搜FindWindow, MouseEvent即可
[解决办法]
代码测试通过,分数拿来。。。
你需要点一下Button1才会自动点击(20,40)这个点。
你可以再修改,用输入框来决定点哪个点。这样总比放在窗体的Load事件里强。
不懂接着问。。。。

C# code
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Runtime.InteropServices;namespace 点击{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        [DllImport("User32")]        public extern static void mouse_event(int dwFlags, int dx, int dy, int dwData, IntPtr dwExtraInfo);        [DllImport("User32")]        public extern static void SetCursorPos(int x, int y);        [DllImport("User32")]        public extern static bool GetCursorPos(out POINT p);        [StructLayout(LayoutKind.Sequential)]        public struct POINT        {            public int X;            public int Y;        }        public enum MouseEventFlags        {            Move = 0x0001,            LeftDown = 0x0002,            LeftUp = 0x0004,            RightDown = 0x0008,            RightUp = 0x0010,            MiddleDown = 0x0020,            MiddleUp = 0x0040,            Wheel = 0x0800,            Absolute = 0x8000        }        private void AutoClick(int x, int y)        {            POINT p = new POINT();            GetCursorPos(out p);            try            {                SetCursorPos(x, y);                mouse_event((int)(MouseEventFlags.LeftDown | MouseEventFlags.Absolute), 0, 0, 0, IntPtr.Zero);                mouse_event((int)(MouseEventFlags.LeftUp | MouseEventFlags.Absolute), 0, 0, 0, IntPtr.Zero);            }            finally            {                SetCursorPos(p.X, p.Y);            }        }        private void button1_Click(object sender, EventArgs e)        {            AutoClick(20, 40);        }    }}
[解决办法]
自动化测试的应该很好做。我这由一个范例,如果想要你可以照着改改

读书人网 >C#

热点推荐