Anmeldungsdatum: Jun 2010
Beiträge: 561
|
VB Code: Imports System.Runtime.InteropServices Public Class Form1 Public pixColor As Color = GetPixelColor(Cursor.Position.X, Cursor.Position.Y) Public modelcolor As Color = GetPixelColor(Cursor.Position.X, Cursor.Position.Y) Public ForeColorStr As String Public model As String <DllImport("gdi32.dll")> _ Private Shared Function CreateDC( _ ByVal lpszDriver As String, _ ByVal lpszDevice As String, _ ByVal lpszOutput As String, _ ByVal lpInitData As IntPtr) As IntPtr End Function <DllImport("gdi32.dll")> _ Private Shared Function DeleteDC(ByVal hdc As IntPtr) As Boolean End Function <DllImport("gdi32.dll")> _ Private Shared Function GetPixel( _ ByVal hdc As IntPtr, _ ByVal nXPos As Integer, _ ByVal nYPos As Integer) As Integer End Function Public Function GetPixelColor(ByVal x As Integer, ByVal y As Integer) As Color Dim hdcScreen As IntPtr = CreateDC("Display", Nothing, Nothing, IntPtr.Zero) Dim colorRef As Integer = GetPixel(hdcScreen, x, y) DeleteDC(hdcScreen) Return Color.FromArgb(colorRef And &HFF, _ (colorRef And &HFF00) >> 8, (colorRef And &HFF0000) >> 16) End Function Public Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) Public Const MOUSEEVENTF_LEFTDOWN = &H2 Public Const MOUSEEVENTF_LEFTUP = &H4 Public Sub SimulateClick() mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick 'Dim pixColor As Color = GetPixelColor(Cursor.Position.X, Cursor.Position.Y) 'Dim ForeColorStr As String = ColorTranslator.ToHtml(pixColor) 'Label1.Text = ForeColorStr Timer1.Enabled = False Timer2.Enabled = True End Sub Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Int32) As UShort Public Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick Dim modelcolor As Color = GetPixelColor(Cursor.Position.X, Cursor.Position.Y) Dim model As String = ColorTranslator.ToHtml(modelcolor) Label2.Text = model Timer4.Enabled = True End Sub Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick If CBool(GetAsyncKeyState(Keys.F12)) Then Timer1.Enabled = True Dim pixColor As Color = GetPixelColor(Cursor.Position.X, Cursor.Position.Y) Dim ForeColorStr As String = ColorTranslator.ToHtml(pixColor) Label1.Text = ForeColorStr ' Else : Timer1.Enabled = False 'Timer2.Enabled = False End If End Sub Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick If model <> ForeColorStr Then SimulateClick() Timer2.Enabled = False Timer4.Enabled = False Else End If End Sub End Class
habs mal kurz in die VB tags gesetzt, weil cihs so unübersichtlich fand
Achja ich würde das alles in ner Do Loop Schleife machen, ist deutlich schneller und übersichtlicher
|