模仿表单后面的点击

时间:2014-03-21 17:38:46

标签: vb.net bitmap pixel

这篇文章与Visual Basic .NET 2010 有关。

我刚才有几个问题要问你。我想枚举使用我的表单的BackgroundImage属性显示的位图中的每个像素,然后如果当前像素为黑色,我想模拟表单后面的单击。那么,我该怎么做?

例如(这里是一些伪代码):

For Each P As Pixel In Form1.BackgroundImage
    If P.Color = Color.Black Then
        EmulateClickBehindForm(P.Position)
    End If
Next

我的表单目前看起来像这样:

enter image description here

非常感谢帮助。

2 个答案:

答案 0 :(得分:0)

尝试这样的事情:

For Each P As Pixel In Form1.BackgroundImage
    If P.Color = Color.Black Then
        Dim sender As Object = Me
        Dim e As New MouseEventArgs(Windows.Forms.MouseButtons.Left, 1, P.Position.X, P.Position.Y, 0)
        Form_Click(sender, e)
    End If
Next

答案 1 :(得分:0)

解决这个问题:

        Dim Bmp As New Bitmap(Me.BackgroundImage)
        Dim Pos As New Point(Me.Location)
        Dim BmpSize As New Bitmap(Bmp.Width, Bmp.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb)
        For y As Integer = 0 To BmpSize.Height - 1
            For x = 0 To BmpSize.Width - 1
                Dim curPixColor As Color = Bmp.GetPixel(x, y)
                If curPixColor = Color.White Then Continue For
                If IsColorBlack(curPixColor) Then
                    Dim pre = New Point(Pos.X + x, Pos.Y + y)
                    SetCursorPos(pre.X, pre.Y)
                    Application.DoEvents()
                    Threading.Thread.Sleep(50)
                    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
                    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
                End If
            Next
        Next

一些解释:

我列举了backgroundimage中的像素,对于每个类似黑色的像素,我在屏幕上点击鼠标,在图像的位置+像素的位置。

真的很简单,这里有一些伪代码可以说明这个过程:

For each P As Pixel In Form1.BackgroundImage
    If P.Color = Color.Black Then
        Click(Form1.Location.X + P.Location.X, Form1.Location.Y + P.Location.Y)
    End If
Next