Fernsteuern von Programmen

Despair Blue

Mitglied
So hab mich erstmal durch 4 Seiten Threads gekämpft und nix gefunden, wenn ich doch einen thread übersehen habe, so tut es mir aufrichtig leid.

Meine Frage ist ob man in VB.NET programme über Sendkey fernsteuern kann und ob man auch mausklick auf der UI anderer Programme erzwingen kann und wenn ja, dann mit welcher Klasse.

Ich bedank mich schonmal im Vorraus.

mfg
 
Hab das hier im Internet gefunden:

Code:
Imports System.Windows.Forms
Imports System.Threading
Public Class WinControl

    ' This is the function used in order to block the keyboard and mouse:
    Declare Function BlockInput Lib "User32" _
           (ByVal fBlockIt As Boolean) As Boolean
    ' This function will block the keyboard and mouse untill a window with
    ' the specify caption will appear or the given time in seconds has 
    ' past ( 0 seconds - wait forever).
    ' If the window with the caption appears than the given key is send 
    ' to it and the input block is removed.
    Public Shared Function Wait2Send(ByVal caption As String, _
              ByVal keys As String, ByVal seconds As Integer, ByVal time_space As Integer)

        ' Indicates if the window with the given caption was found
        Dim success As Boolean = False
        Dim strokes() As String = Split(keys, ";")
        ' Start time of the function
        Dim now As DateTime = DateTime.Now
        Dim i As Integer
        ' Begining of keyboard and mouse block
        BlockInput(True)

        While (success = False And (DateTime.Now.Subtract(now).Seconds _
                                               < seconds Or seconds = 0))
            Try
                ' Activating the window with desired function
                ' if the window is not found an exception is thrown.
                AppActivate(caption)
                Thread.Sleep(500)

                ' Sending desired key stroke to the application window
                For i = 0 To strokes.Length - 1
                    AppActivate(caption)
                    SendKeys.SendWait(strokes(i))
                    Thread.Sleep(time_space)
                Next i
                ' Indicates the window was found and keys sent
                success = True

            Catch
                ' Assuming window was not found and sleep for 100 miliseconds
                System.Threading.Thread.Sleep(1000)
            End Try
        End While
        ' Release the keyboard block
        BlockInput(False)

    End Function

End Class

Wie das mit dem Mausklick geht weiss ich nicht, da muss man sich schon tiefer mit der Windows API befassen. Meiner Meinung nach kannst du aber alles was du mit der Maus machst, auch mit der Tastatur machen, sofern es nicht um irgendwelche 3D-Shooter geht ;)
 
Zurück