Ein Bekannter hat die gewünschte Funktion mal in c# geschrieben, laeuft auch. Nun habe ich diesen Source in vb.net wandeln lassen und folgendes kahm heraus (ein paar Fehler habe ich schon behoben):
Code:
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Imports System.Threading
Namespace MacroEngineWF
Class MacroEngine
<DllImport("User32.dll")> _
Private Shared Function GetAsyncKeyState(ByVal key As Integer) As Short
End Function
Private Const VK_RETURN As Integer = &HD
Private Const VK_ESCAPE As Integer = &H1B
Private Const VK_SHIFT As Integer = &H10
Private Const VK_CONTROL As Integer = &H11
Private Const VK_MENU As Integer = &H12
Private Const VK_1 As Integer = &H31
Private Const VK_A As Integer = &H41
Private _pressedKey As New List(Of Integer)()
Private _newKeys As New List(Of Integer)()
Private running As Boolean = True
Private _trackedKeys As New List(Of Integer)() From { _
VK_RETURN, _
VK_ESCAPE, _
VK_SHIFT, _
VK_CONTROL, _
VK_MENU, _
VK_1, _
VK_A _
}
Public Sub New()
End Sub
Public Sub Run()
While running
UpdateKeys()
Thread.Sleep(50)
End While
End Sub
Private Sub UpdateKeys()
Dim downKeys = GetAllDownKeys()
For Each key As Object In downKeys
If Not _pressedKey.Contains(key) Then
KeyWasPressed(key)
_pressedKey.Clear()
_pressedKey.AddRange(downKeys)
End If
Next
End Sub
Private Sub KeyWasPressed(ByVal key As Integer)
If key = VK_ESCAPE Then
running = False
End If
If key = VK_1 Then
If GetAllDownKeys().Contains(VK_SHIFT) Then
SendMessage("This is in control!")
Else
SendMessage("Hello World!")
End If
End If
End Sub
Private Function GetAllDownKeys() As IEnumerable(Of Integer)
For Each key As Object In _trackedKeys
If IsKeyDown(key) Then
yield Return key
End If
Next
End Function
Private Function IsKeyDown(ByVal key As Integer) As Boolean
Return (GetAsyncKeyState(key) And &H8000) > 0
End Function
Private Sub SendMessage(ByVal message As [String])
SendKeys.Send(message)
End Sub
End Class
End Namespace
Partial Public Class Form1
Inherits Form
Private _engine As New MacroEngine()
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
_engine.Run()
Close()
End Sub
End Class
Screen der derzeitigen Fehlerausgaben von Visual Studio:
[Only registered and activated users can see links. Click Here To Register...]
Weiß da einer, wie ich die Fehler beheben kann?