模拟鼠标点击问题 C#

kiba518 2008-09-23 11:49:37
我想做个 C#程序
程序运行时
自动 点击某网页的 固定坐标

50分求详细代码
...全文
1429 34 打赏 收藏 转发到动态 举报
写回复
用AI写文章
34 条回复
切换为时间正序
请发表友善的回复…
发表回复
浮生若梦丶 2008-09-23
  • 打赏
  • 举报
回复
up
ZengHD 2008-09-23
  • 打赏
  • 举报
回复
mouse_event
更方法的是使用WebBrowser控件
yoyoalphax 2008-09-23
  • 打赏
  • 举报
回复
[Quote=引用 26 楼 legendcyqkt 的回复:]
代码测试通过,分数拿来。。。
你需要点一下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 点…
[/Quote]

改自经典的Simulate Mouse...嘿嘿~csdn上有下的:)
kiba518 2008-09-23
  • 打赏
  • 举报
回复
呵呵 明天来结贴 大家都有分

非常感谢大家
r_swordsman 2008-09-23
  • 打赏
  • 举报
回复
呵呵,想做投票的东西吧?不用这么麻烦
lidup 2008-09-23
  • 打赏
  • 举报
回复
呵呵,我接
kiba518 2008-09-23
  • 打赏
  • 举报
回复
加分是一定的

给分也是一定的 呵呵

多谢大家了
woshiyule 2008-09-23
  • 打赏
  • 举报
回复
给个建议你,直接用按键精灵吧
XPingguo 2008-09-23
  • 打赏
  • 举报
回复
楼上是可爱的人
楼主加分给他
lidup 2008-09-23
  • 打赏
  • 举报
回复
自动化测试的应该很好做。我这由一个范例,如果想要你可以照着改改
legendcyqkt 2008-09-23
  • 打赏
  • 举报
回复
代码测试通过,分数拿来。。。
你需要点一下Button1才会自动点击(20,40)这个点。
你可以再修改,用输入框来决定点哪个点。这样总比放在窗体的Load事件里强。
不懂接着问。。。。

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);
}
}
}
lw549 2008-09-23
  • 打赏
  • 举报
回复
传说中有个地方叫msdn,搜FindWindow, MouseEvent即可
XPingguo 2008-09-23
  • 打赏
  • 举报
回复
1.用Hook捕捉到鼠标点击
2.用GetCursorPos获鼠标点击时的坐标
3.用SetCursorPos设置鼠标的坐标
4.用mouse_event模拟鼠标点击
ZengHD 2008-09-23
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 kiba518 的回复:]
16楼的大哥
这段话我看过了。。
可是我不懂啊

我用Application.DoEvents();


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

Application.DoEvents();和显示新窗体没有关系

qiqundelang 2008-09-23
  • 打赏
  • 举报
回复
给钱我给你原代码
或者帮你做
kiba518 2008-09-23
  • 打赏
  • 举报
回复
华丽的UP
kiba518 2008-09-23
  • 打赏
  • 举报
回复
ding
kiba518 2008-09-23
  • 打赏
  • 举报
回复
16楼的大哥
这段话我看过了。。
可是我不懂啊

我用Application.DoEvents();


可是并没有出现新窗体
能不能在详细点
zx005 2008-09-23
  • 打赏
  • 举报
回复
不知道你点的啥,如果是按钮的话,在WebBrowser中要比你模拟按键方便的多!
kiba518 2008-09-23
  • 打赏
  • 举报
回复
点击我实现了
Application.DoEvents();
这个是什么问题

问题越来越多了 明天加分
在结贴
加载更多回复(14)

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧