返回首页

我希望做一个宏,将移动鼠标,点击,使用键。点击某处有一组像素的颜色。像所有的红玫瑰在草地景观的色调。目的,是良好的游戏,也许照片* H *运算。我能得到更多的创意,但这些都是基本的东西。

我应该使用哪种语言?你会推荐什么库

正是我希望这个宏做的。
1。切换到这是打开基于其名称或任何一个窗口或程序,以确定它。
2。点击某处曾经根据一组颜色。
3。睡觉
4。打键盘上的键
5。重复
6。如果没有找到的颜色,点击组,它应该打在键盘上一个键,我猜,我自己能想出一些google搜索,。如果这样做,elses,所有DAT

这是我喜欢编程的原因,因为你可以做疯狂的事情,即使你不能让这个完美的,只是指出我的地方,这样我就可以学习,或用什么来帮助我创建这个宏。

发现这对谷歌的代码片段,它supposively我想要的一切。我将如何得到这个工作,2010年在VB快递吗?与申请表格,和一个按钮,我不能得到它的工作。这是不正确的代码,我的需求,我的选择吗?

在那里我找到的代码:

Functions:

 

FindControl 

ClickControl 

SendKey 

SendChar 

SendKeyString 

SendString 

GetScreenshot (Won't work when window is minimized) 

GetPixelColor (Won't work when window is minimized) 

GetControlSize 

PixelSearch 

ImageSearch (Added this since I thought it might be useful) (Won't work when window is minimized) 

应该使用这些功能的代码。

{C}
被我猜某些功能的类?

Imports System

Imports System.Runtime.InteropServices

Imports Microsoft.Win32

Imports System.Windows.Forms

Imports System.Drawing

Imports System.Collections

 

Namespace WindowsControls

    Class Control

        Public Sub New(ByVal Handle As IntPtr)

            hWnd = Handle

        End Sub

 

        Private hWnd As IntPtr = IntPtr.Zero

        Public Property ControlHandle() As IntPtr

            Get

                Return hWnd

            End Get

            Set(ByVal value As IntPtr)

                hWnd = value

            End Set

        End Property

 

#Region "Interop"

 

        Const WM_KEYDOWN As UInteger = &H100

        Const WM_KEYUP As UInteger = &H101

        Const WM_PAINT As Int32 = &HF

        Const WM_LBUTTONDOWN As Int32 = &H201

        Const WM_LBUTTONUP As Int32 = &H202

 

        <DllImport("User32.dll", SetLastError:=True)> _

        Private Shared Function PrintWindow(ByVal hwnd As IntPtr, ByVal hDC As IntPtr, ByVal nFlags As UInteger) As Boolean

        End Function

 

        <DllImport("user32.dll", SetLastError:=True)> _

        Private Shared Function PostMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean

        End Function

 

        <DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=False)> _

        Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Int32, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr

        End Function

 

        <DllImport("user32.dll", SetLastError:=True)> _

        Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, ByVal childAfter As IntPtr, ByVal className As String, ByVal windowTitle As IntPtr) As IntPtr

        End Function

 

        <DllImport("user32.dll")> _

        Private Shared Function GetWindowRect(ByVal hWnd As IntPtr, ByRef lpRect As RECT) As <MarshalAs(UnmanagedType.Bool)> Boolean

        End Function

        <StructLayout(LayoutKind.Sequential)> _

        Private Structure RECT

            Public Left As Integer

            Public Top As Integer

            Public Right As Integer

            Public Bottom As Integer

        End Structure

 

#End Region

 

        ''' <summary>

        ''' Gets the control handle

        ''' </summary>

        ''' <param name="parentHandle">The handle of the parent window</param>

        ''' <param name="controlName">The name of the control</param>

        ''' <returns>The control handle</returns>

        Public Shared Function FindControl(ByVal parentHandle As IntPtr, ByVal controlName As String) As IntPtr

            Return FindWindowEx(parentHandle, IntPtr.Zero, controlName, IntPtr.Zero)

        End Function

 

        ''' <summary>

        ''' Clicks control at specified coordinates

        ''' </summary>

        ''' <param name="hWnd">The window handle</param>

        ''' <param name="x">The x-coordinate</param>

        ''' <param name="y">The y-coordinate</param>

        Public Sub ClickControl(ByVal x As Integer, ByVal y As Integer)

            Dim coords As Integer = (y << 16) + x

            Dim lParam As New IntPtr(coords)

            PostMessage(hWnd, WM_LBUTTONDOWN, IntPtr.Zero, lParam)

            PostMessage(hWnd, WM_LBUTTONUP, IntPtr.Zero, lParam)

        End Sub

 

        ''' <summary>

        ''' Clicks the control at a specified point

        ''' </summary>

        ''' <param name="p">The point to click</param>

        Public Sub ClickControl(ByVal p As Point)

            ClickControl(p.X, p.Y)

        End Sub

 

        ''' <summary>

        ''' Sends a specified key to the control

        ''' </summary>

        ''' <param name="k">The key to send</param>

        Public Sub SendKey(ByVal k As Keys)

            PostMessage(hWnd, WM_KEYDOWN, New IntPtr(CInt(k)), IntPtr.Zero)

            PostMessage(hWnd, WM_KEYUP, New IntPtr(CInt(k)), IntPtr.Zero)

        End Sub

 

        ''' <summary>

        ''' Sends a character to the control

        ''' </summary>

        ''' <param name="c">The character to send</param>

        Public Sub SendChar(ByVal c As Char)

            Const WM_CHAR As UInteger = &H102

            PostMessage(hWnd, WM_CHAR, New IntPtr(Convert.ToInt32(c)), IntPtr.Zero)

        End Sub

 

        ''' <summary>

        ''' Sends a string to the control as keys

        ''' </summary>

        ''' <param name="s">The string to send</param>

        Public Sub SendKeyString(ByVal s As String)

            s = s.ToLower()

            For Each c As Char In s

                SendKey(DirectCast((Convert.ToInt32(c) - 32), Keys))

            Next

        End Sub

 

        ''' <summary>

        ''' Sends a string to the specified control

        ''' </summary>

        ''' <param name="s">The string to send</param>

        Private Sub SendString(ByVal s As String)

            For Each c As Char In s

                SendChar(c)

            Next

        End Sub

 

        ''' <summary>

        ''' Takes a screenshot of the control

        ''' </summary>

        ''' <returns>A bitmap of the control</returns>

        Public Function GetScreenshot() As Bitmap

            Dim controlSize As Size = GetControlSize()

            Dim bmp As New System.Drawing.Bitmap(controlSize.Width, controlSize.Height)

            Dim g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(bmp)

            Dim dc As IntPtr = g.GetHdc()

 

            SendMessage(hWnd, WM_PAINT, IntPtr.Zero, IntPtr.Zero)

            PrintWindow(hWnd, dc, 0)

 

            g.ReleaseHdc()

            g.Dispose()

            Return bmp

        End Function

 

        ''' <summary>

        ''' Gets the color of a selected pixel

        ''' </summary>

        ''' <param name="x">The x-coordinate</param>

        ''' <param name="y">The y-coordinate</param>

        ''' <returns>The color of the pixel</returns>

        Public Function GetPixelColor(ByVal x As Integer, ByVal y As Integer) As Color

            Return GetScreenshot().GetPixel(x, y)

        End Function

 

        ''' <summary>

        ''' Gets the pixel color of a specified point

        ''' </summary>

        ''' <param name="p">The point of the pixel</param>

        ''' <returns>The color of the pixel</returns>

        Public Function GetPixelColor(ByVal p As Point) As Color

            Return GetPixelColor(p.X, p.Y)

        End Function

 

        ''' <summary>

        ''' Gets the size of the control

        ''' </summary>

        ''' <returns>The size of the control</returns>

        Public Function GetControlSize() As Size

            Dim rect As RECT

            GetWindowRect(hWnd, rect)

            Return New Size(rect.Right - rect.Left, rect.Bottom - rect.Top)

        End Function

 

        ''' <summary>

        ''' Gets the points on the control with the specified color

        ''' </summary>

        ''' <param name="c">The color to search for</param>

        ''' <returns>The points of the pixels with the specified color</returns>

        Public Function PixelSearch(ByVal c As Color) As Point()

            Dim list As New System.Collections.ArrayList()

            Dim controlSize As Size = GetControlSize()

            Dim controlImage As Bitmap = GetScreenshot()

            For y As Integer = 0 To controlSize.Height - 1

                For x As Integer = 0 To controlSize.Width - 1

                    If controlImage.GetPixel(x, y) = c Then

                        list.Add(New Point(x, y))

                    End If

                Next

            Next

            Return DirectCast(list.ToArray(GetType(Point)), Point())

        End Function

 

        ''' <summary>

        ''' Searches for an image

        ''' </summary>

        ''' <param name="b">The image to search for in the control</param>

        ''' <returns>The points at the upper left corner of the image</returns>

        Public Function ImageSearch(ByVal b As Bitmap) As Point()

            Dim controlSize As Size = GetControlSize()

            Dim controlImage As Bitmap = GetScreenshot()

            Dim list As New ArrayList()

            For y As Integer = 0 To controlSize.Height - 1

                For x As Integer = 0 To controlSize.Width - 1

                    If controlImage.GetPixel(x, y) = b.GetPixel(0, 0) Then

                        Dim validPoint As Boolean = True

                        For by As Integer = 0 To b.Height - 1

                            For bx As Integer = 0 To b.Width - 1

                                If x + bx >= controlImage.Width OrElse y + by >= controlImage.Height Then

                                    validPoint = False

                                    Exit For

                                ElseIf controlImage.GetPixel(x + bx, y + by) <> b.GetPixel(bx, by) Then

                                    validPoint = False

                                    Exit For

                                End If

                            Next

                            If Not validPoint Then

                                Exit For

                            End If

                        Next

                        If validPoint Then

                            list.Add(New Point(x, y))

                        End If

                    End If

                Next

            Next

            Return DirectCast(list.ToArray(GetType(Point)), Point())

        End Function

 

        ''' <summary>

        ''' Searches for an image

        ''' </summary>

        ''' <param name="i">The image to search for in the control</param>

        ''' <returns>The points at the upper left corner of the image</returns>

        Public Function ImageSearch(ByVal i As Image) As Point()

            Return ImageSearch(DirectCast(i, Bitmap))

        End Function

    End Class

End Namespace

 


太多的P / Invoke意味着参数调用?我同意它看起来并不像VB.NET代码,大量的XML扔在那里。

我只知道,HTML和CSS。

我看了其他语言,阅读它们。我知道,代码容器,以及如何开始/结束。我知道,进口顶端。我知道功能可以有输入和输出。我知道,事情被称为,或挂了很多以为所欲为。像某些功能,您有链接到他们,我也认为,如果你使用的命名空间,或者如果你使用的进口,你没有链接到他们有时或尽可能多。有吨结构代码的方式,如果报表。我知道,一类是所有硬的东西去,和你链接到他们有时只是使用它的功能。您链接到他们的图书馆使用功能,或任何。等等等等,我读了很多关于编码,但我忘了大部分。 COUT LT,LT的printf writeDocument呸,我忘了

此外,我不知道很多的vocabularly与编码相关。想如果你说你将在四溢的命名空间的类对象的子基地。我要去O_O,只是知道我有谷歌的一切你的说法= _ =

谢谢你看这...和那些看着这个网站上,在我的最后一个问题

回答

评论会员:游客 时间:2012/02/07
SAKryukov:答案很简单,但也不是很容易实现。这是可行的,实际上只有一个办法。我知道100%的路线图。据我所知,你需要录制和播放系统中的任何应用的宏(如你提到的游戏和Photoshop,这是不是唯一的球员,甚至对自己的市场)。您可以使用。NET的任何语言​​,C#的首选,但你也需要一些本地代码的一块。我想用C或Delphi,但你可以使用任何编程系统全面的生产Windows本地代码。你需要两种行动。首先,你需要记录在原始的水平,没有别的所有输入事件。它使用Windows挂钩的方式做。看到{A1}]现在的问题是:你可以安装一个钩子,用P/调用WindowsAPI的调用SetWindowsHookEx,{A2}这将做工精细,但只挂钩事件的过程。安装一个系统全局钩子,你需要在原生的DLL调用此功能,根据微软的文档。你可以使用这个DLL。NET应用程序,并建立一些沟通与本地代码,将每个事件调用您的。NET回调。你应该明白,回调将在不同的线程调用,所以你应该使用正确的线程同步。这样,您将可以记录事件信息,为你需要的宏记录。它的第二部分是播放录制的宏。你应该使用的P/援用的API函数与SendInput,没有别的。见{A3的}](P/Invoke的已经为你写的)。要了解更多的P/Invoke的:{A4纸},{A5的}](不用担心,手册是2003年还是不够好)。也看到这个CodeProject上的文章:{A6的}。这基本上它mdash;去上班!祝你好运,mdash;水杨酸|SAKryukov
Tristan32写道:: |约翰・西蒙斯/取缔程序员
评论会员:游客 时间:2012/02/07
后退从这个项目,因为它是明显的(和我并不想要的意思),你不知道任何有关编程。"知道HTML和CSS"并不意味着你有任何的把握上编写的应用程序需要什么样的。最好的事情,你能做的就是采取了一堆的编程类