本文介绍了我想创建一个可以执行以下操作的宏,我应该使用什么?吨的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想创建一个移动鼠标的宏,单击,使用键。单击具有组像素颜色的某个位置。就像草地上的玫瑰中所有的红色色调一样。目的,适合游戏,也许照片* h * op。我可以更有创意,但这些是基本的东西。 我应该使用哪种语言?你会推荐哪些图书馆? 我想要这个宏做什么。 1.切换到根据其名称或其他任何标识打开的窗口或程序。 2.根据一组颜色单击某处。 3 。睡觉 4.按键盘上的键 5.重复 6.如果它找不到颜色组点击它,它应该击中键盘上的一个键,我猜我可以通过一些谷歌搜索来解决这个问题。做ifs,elses和所有数据。 这是我喜欢编程的原因之一,因为你可以做疯狂的事情,即使你不能做到这一点,只是指着我在某处,这样我就可以学习,或者用某些东西来帮助我创建这个宏。 在google上找到这个代码片段,它绝对会做我想做的一切。我如何在VB Express 2010中使用它?使用表单应用程序和按钮我无法使其工作。这段代码是否符合我的需求,请告诉我替代方案? 我在哪里找到代码: http://thebotnet.com/programming/1810-vb-net-creating-rs-bot/ 功能: FindControl ClickControl SendKey SendChar SendKeyString SendString GetScreenshot(赢取)当窗口最小化时不起作用) GetPixelColor(当窗口最小化时不起作用) GetControlSize PixelSearch ImageSearch(添加这个,因为我认为它可能有用)(窗口最小化时无法工作) 应该使用这些功能的代码。 Imports WindowsControls ' 首先,您必须使用Control.FindWindow找到窗口的句柄 Dim 句柄作为 IntPtr = Controls.FindWindow(WebBrowser1.Handle, ControlNameHere) ' 创建一个新控件对象 Dim MyControl 作为 新控件(句柄) ' 开始自动化这里的东西(这个代码没有做任何事情) MyControl.ClickControl( 123 , 456 ) System.Threading.Thread.Sleep( 1000 ) Dim MyColor As Color = MyControl.GetPixelColor( 12 , 34 ) Dim ClickPoint As Point = MyControl.PixelSearch(MyColor)( 0 ) MyControl.ClickControl(ClickPoint) Dim ClickPoint2 正如 Point = MyControl.ImageSearch(My.Resources.ExamplePic)( 0 ) MyControl.ClickControl(ClickPoint2) 上课时我猜是否有一些功能? Imports 系统 Imports System.Runtime.InteropServices Imports Microsoft.Win32 Imports System.Windows.Forms Imports System.Dr awing Imports System.Collections 命名空间 WindowsControls 类控制 公共 Sub 新( ByVal 句柄作为 IntPtr ) hWnd =句柄 结束 Sub 私有 hWnd As IntPtr = IntPtr .Zero 公共 属性 ControlHandle()作为 IntPtr 获取 返回 hWnd 结束 获取 设置( ByVal value As IntPtr ) hWnd = value 结束 设置 结束 属性 #RegionInterop Const WM_KEYDOWN 作为 UInteger =& H100 Const WM_KEYUP 作为 UInteger =& H101 Const WM_PAINT As Int32 =& HF Const WM_LBUTTONDOWN As Int32 =& H201 Const WM_LBUTTONUP 作为 Int32 =& H202 < DllImport( User32.dll, SetLastError:= TRUE)> _ 私有 共享 功能 PrintWindow( ByVal hwnd As IntPtr , ByVal hDC 作为 IntPtr , ByVal nFlags 作为 UInteger )作为 布尔 结束 功能 < DllImport( user32.dll,SetLastError:= True)> _ 私有 共享 功能 PostMessage( ByVal hWnd As IntPtr , ByVal 消息作为 UInteger , ByVal wParam 作为 IntPtr , ByVal lParam As IntPtr )作为< MarshalAs(UnmanagedType.Bool)> 布尔 结束 功能 < DllImport( user32.dll,CharSet:= CharSet。 Auto,SetLastError:= False)> _ 私有 共享 功能 SendMessage( ByVal hWnd As IntPtr , ByVal 消息作为 Int32 , ByVal wParam 作为 IntPtr , ByVal lParam As IntPtr )正如 IntPtr 结束 功能 < DllImport( user32.dll, SetLastError:= TRUE)> _ 私有 共享 功能 FindWindowEx( ByVal parentHandle As IntPtr , ByVal childAfter As IntPtr , ByVal className 作为 字符串, ByVal windowTitle As IntPtr )正如 IntPtr 结束 功能 < DllImport( user32.dll) > _ 私有 共享 功能 GetWindowRect( ByVal hWnd As IntPtr , ByRef lpRect As RECT) As < MarshalAs (UnmanagedType.Bool)GT; 布尔 结束 功能 < StructLayout(LayoutKind.Sequential)> _ 私有 结构 RECT 公开左作为 整数 公开顶部作为 整数 公开正确作为 整数 公开底部作为 整数 结束 结构 #End Region ''' < 摘要 > ''' 获取控件句柄 ''' < / summary > ''' < param name =parentHandle > 父窗口的句柄< / param > ''' < param name =controlName > 控件的名称< / param > ''' < 返回 > 控制句柄< / returns > 公开 共享 功能 FindControl( ByVal parentHandle As IntPtr , ByVal controlName 作为 字符串)作为 IntPtr 返回 FindWindowEx(parentHandle, IntPtr .Zero,controlName, IntPtr .Zero) 结束 功能 ''' < 摘要 > ''' 在指定坐标点击控件 ''' < / summary > ''' < param name =hWnd > 窗口句柄< / param > ' '' < param name =x > x坐标< / param > ''' < param name =y > y坐标< / param > 公开 Sub ClickControl( ByVal x As Integer , ByVal y 作为 整数) Dim coords As Integer =(y<< 16 )+ x Dim lParam As 新 IntPtr (coords) PostMessage(hWnd,WM_LBUTTONDOWN, IntPtr .Zero,lParam) PostMessage(hWnd,WM_LBUTTONUP, IntPtr .Zero,lParam) 结束 Sub '' ' < 摘要 > ''' 点击控件在指定点 ''' < / summary > ''' < param name =p > 要点击< / param > 公共 Sub ClickControl ( ByVal p As Point) ClickControl(pX,pY) 结束 Sub ''' < 摘要 > ; ''' 将指定的密钥发送到控件 ''' < / summary > '' ' < param name =k > 要发送的密钥< / param > 公共 Sub SendKey( ByVal k As Keys) PostMessage(hWnd,WM_KEYDOWN, New IntPtr ( CInt (k)), IntPtr .Zero) PostMessage(hWnd,WM_KEYUP,新 IntPtr ( CInt (k)), IntPtr .Zero) 结束 Sub ''' < 摘要 > ''' 将字符发送到控件 ''' < / summary > ''' < param name = c > 要发送的字符< / param > 公开 Sub SendChar( ByVal c As 查r ) Const WM_CHAR As UInteger =& H102 PostMessage(hWnd,WM_CHAR,新 IntPtr (Convert.ToInt32(c)), IntPtr .Zero) 结束 Sub ''' < 摘要 > ''' 将字符串作为键发送到控件 ''' < / summary > ''' < param name =s > 要发送的字符串< / param > 公开 Sub SendKeyString( ByVal s As 字符串)s = s.ToLower() 对于 每个 c 作为 字符 在 s SendKey( DirectCast ((Convert.ToInt32(c) - 32 ),Keys)) 下一步 结束 Sub ''' < 摘要 > ''' 将字符串发送到指定的控件 ''' < / summary > ''' < param name = s > 要发送的字符串< / param > 私人 Sub SendString( ByVal s As 字符串) 对于 每个 c 作为 字符 在 s SendChar(c ) 下一步 结束 Sub ''' < 摘要 > ''' 获取控件的屏幕截图 ''' < / summary > ''' < 返回 > 控件的位图< / returns > 公共 功能 GetScreenshot()作为位图 Dim controlSize As Size = GetControlSize() Dim bmp As 新 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() 返回 bmp 结束 功能 ''' < 摘要 > ''' 获取所选像素的颜色 ''' < / summary > ''' < param name =x > x坐标< / param > ''' < param name =y > y坐标< / param > ''' < 返回 > 像素的颜色< / returns > 公共 功能 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 Too much p/invoke does that mean param invoking? I agree it doesn’t look like VB.net code, lots of XML thrown in there. I only know, HTML, CSS. I’ve looked at other languages, and read up on them. I know that code has containers, and ways to start/end it. I know that imports go at the top. I know functions can have inputs, and outputs. I know that things are called, or linked to a lot in order to do whatever. Like some functions you have to link to them, also i think if you use namespaces or if you use imports you don’t have to link to them sometimes or as much. There’s tons of ways to structure code, if statements. I know that a class is where all the hard stuff goes, and you link to them sometimes just to use a function in it. Libraries you link to them to use functions, or whatever. Etc etc. I read up a lot on coding but i forget most of it. cout << printf writeDocument, bah i forget. Also I don’t know a lot of the vocabularly associated with coding. Like if you say your putting a sub base in a class object overflowing the namespace. I’m gonna O_O, just be aware I’d have to google everything your saying =_= Thank you for looking at this... And to those that looked at my last question on this website 解决方案 Back off from this project, because it’s obvious (and I’m not trying to be mean) that you don’t know anything about programming. \"Knowing html and CSS\" does NOT mean you have any kind of grasp on what it takes to write an application. The best thing you can do is to take a BUNCH of programming classes.The answer is very simple, but the implementation is not very easy. This is doable, and practically only one way. I know 100% of the road map. As I understand, you need to record and play macro over any applications in the system (as you mentioned games and Photoshop, which is not the only player even on its own market). You can use .NET, any language, C# preferred, but you also need a piece of some native code. I would use C++ or Delp but you can use any fully-fledged programming system producing Windows native code. You need two kinds of action. First, you need to record all input events on raw level, and nothing else. The way to do it is using Windows Hooks. See http://msdn.microsoft.com/en-us/library/windows/desktop/ms632589%28v=vs.85%29.aspx[^]. Here is the problem: you can install a hook using P/Invoked Windows API SetWindowsHookEx, see http://msdn.microsoft.com/en-us/library/windows/desktop/ms644960%28v=vs.85%29.aspx#installing_releasing[^]. This would work fine, but only to hook up events of your process. To install a system-global hook, you need to call this function in a native DLL, according to Microsoft documentation. You can use this DLL in your .NET application and establish some communication with its native code which would call your .NET callback on each of the events. You should understand that the callback will be called in different threads, so you should use proper thread synchronization. This way, you will be able to record the event information needed for you macro record. Second part of it is playing the recorded macro. You should use P/Invoked API function SendInput, and nothing else. See http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^], http://pinvoke.net/default.aspx/user32.sendinput[^] (P/Invoke is already written for you). To learn more of P/Invoke: http://en.wikipedia.org/wiki/P/invoke[^], http://msdn.microsoft.com/en-us/library/Aa712982[^] (don’t worry, manual of 2003 is still good enough). See also this CodeProject article: Essential P/Invoke[^]. That’s basically it — get to work! Good luck, —SATristan32 wrote: So your saying if I maximized a game on my computer, there’s no code I can use that can detect a pixel color from that game, and click on it?This is just one of the relatively difficult problems you would need to solve. You would need to P/Invoke or use directly in your native code the following Windows API: GetWindowDC(HWND) (user32), http://msdn.microsoft.com/en-us/library/dd144947%28v=vs.85%29.aspx[^] ReleaseDC(HWND, HDC) (user32), http://msdn.microsoft.com/en-us/library/dd162920%28v=vs.85%29.aspx[^] GetPixel(HDC, int, int) (gdi32), http://msdn.microsoft.com/en-us/library/dd144909%28v=vs.85%29.aspx[^]. Unfortunately, no one will do it all for you. You should be able to dig out a good deal of Windows API to use — mostly or all by yourself. —SAI want to make a macro that will move the mouse, click, use keys. Click somewhere that has a group Pixel colors. Like all the shades of red in a rose on a grassy landscape. Purpose, be good for games, and maybe photos*h*op. I could get more creative but those are the basic things.Which language should I use? What libraries would you recommend?Exactly what I would want this macro to do.1. Switch to a window or program that's opened based off its name or whatever to identify it.2. Click somewhere once based off a group of colors.3. Sleep4. Hit a key on the keyboard5. Repeat6. And if it DOESN'T find the group of colors to click, it should hit a key on the keyboard, I'm guessing I could figure that out myself with some googling. Doing ifs, elses, and all dat.This is one of the reasons i like programming because you can do crazy things, even if you can't make this perfect, just point me somewhere so i can learn, or use something to help me create this macro.Found this code snippet on google, it supposively does everything I want. How would I get this to work in VB express 2010? With a form application, and a button I couldn't get it to work. Is this code incorrect for my needs, show me alternatives?Where i found the code: http://thebotnet.com/programming/1810-vb-net-creating-rs-bot/Functions:FindControlClickControlSendKeySendCharSendKeyStringSendStringGetScreenshot (Won't work when window is minimized)GetPixelColor (Won't work when window is minimized)GetControlSizePixelSearchImageSearch (Added this since I thought it might be useful) (Won't work when window is minimized)The code that supposed to use those functions.Imports WindowsControls'First you must find the window's handle by using Control.FindWindowDim Handle As IntPtr = Controls.FindWindow(WebBrowser1.Handle, "ControlNameHere")'Create a new Controls objectDim MyControl As New Controls(Handle)'Start automating stuff here (this code doesn't do anything really)MyControl.ClickControl(123, 456)System.Threading.Thread.Sleep(1000)Dim MyColor As Color = MyControl.GetPixelColor(12, 34)Dim ClickPoint As Point = MyControl.PixelSearch(MyColor)(0)MyControl.ClickControl(ClickPoint)Dim ClickPoint2 As Point = MyControl.ImageSearch(My.Resources.ExamplePic)(0)MyControl.ClickControl(ClickPoint2)The class were I'm guessing some of the functions were made?Imports SystemImports System.Runtime.InteropServicesImports Microsoft.Win32Imports System.Windows.FormsImports System.DrawingImports System.CollectionsNamespace 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 ClassEnd NamespaceToo much p/invoke does that mean param invoking? I agree it doesn't look like VB.net code, lots of XML thrown in there.I only know, HTML, CSS.I've looked at other languages, and read up on them. I know that code has containers, and ways to start/end it. I know that imports go at the top. I know functions can have inputs, and outputs. I know that things are called, or linked to a lot in order to do whatever. Like some functions you have to link to them, also i think if you use namespaces or if you use imports you don't have to link to them sometimes or as much. There's tons of ways to structure code, if statements. I know that a class is where all the hard stuff goes, and you link to them sometimes just to use a function in it. Libraries you link to them to use functions, or whatever. Etc etc. I read up a lot on coding but i forget most of it. cout << printf writeDocument, bah i forget.Also I don't know a lot of the vocabularly associated with coding. Like if you say your putting a sub base in a class object overflowing the namespace. I'm gonna O_O, just be aware I'd have to google everything your saying =_=Thank you for looking at this... And to those that looked at my last question on this website 解决方案 Back off from this project, because it's obvious (and I'm not trying to be mean) that you don't know anything about programming. "Knowing html and CSS" does NOT mean you have any kind of grasp on what it takes to write an application. The best thing you can do is to take a BUNCH of programming classes.The answer is very simple, but the implementation is not very easy. This is doable, and practically only one way. I know 100% of the road map.As I understand, you need to record and play macro over any applications in the system (as you mentioned games and Photoshop, which is not the only player even on its own market). You can use .NET, any language, C# preferred, but you also need a piece of some native code. I would use C++ or Delphi, but you can use any fully-fledged programming system producing Windows native code.You need two kinds of action. First, you need to record all input events on raw level, and nothing else. The way to do it is using Windows Hooks. See http://msdn.microsoft.com/en-us/library/windows/desktop/ms632589%28v=vs.85%29.aspx[^].Here is the problem: you can install a hook using P/Invoked Windows API SetWindowsHookEx, see http://msdn.microsoft.com/en-us/library/windows/desktop/ms644960%28v=vs.85%29.aspx#installing_releasing[^].This would work fine, but only to hook up events of your process. To install a system-global hook, you need to call this function in a native DLL, according to Microsoft documentation. You can use this DLL in your .NET application and establish some communication with its native code which would call your .NET callback on each of the events. You should understand that the callback will be called in different threads, so you should use proper thread synchronization. This way, you will be able to record the event information needed for you macro record.Second part of it is playing the recorded macro. You should use P/Invoked API function SendInput, and nothing else. See http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[^], http://pinvoke.net/default.aspx/user32.sendinput[^] (P/Invoke is already written for you).To learn more of P/Invoke:http://en.wikipedia.org/wiki/P/invoke[^],http://msdn.microsoft.com/en-us/library/Aa712982[^] (don't worry, manual of 2003 is still good enough).See also this CodeProject article: Essential P/Invoke[^].That's basically it — get to work!Good luck,—SATristan32 wrote:So your saying if I maximized a game on my computer, there's no code I can use that can detect a pixel color from that game, and click on it?This is just one of the relatively difficult problems you would need to solve.You would need to P/Invoke or use directly in your native code the following Windows API:GetWindowDC(HWND) (user32), http://msdn.microsoft.com/en-us/library/dd144947%28v=vs.85%29.aspx[^]ReleaseDC(HWND, HDC) (user32), http://msdn.microsoft.com/en-us/library/dd162920%28v=vs.85%29.aspx[^]GetPixel(HDC, int, int) (gdi32), http://msdn.microsoft.com/en-us/library/dd144909%28v=vs.85%29.aspx[^].Unfortunately, no one will do it all for you. You should be able to dig out a good deal of Windows API to use — mostly or all by yourself.—SA 这篇关于我想创建一个可以执行以下操作的宏,我应该使用什么?吨的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-14 15:57