VB 2008 - Keybind/Hotkey funktioniert nur dauerhaft?

02/20/2011 18:13 Feuerkerk#16
Quote:
Originally Posted by .SaFe View Post
siehe da^^
Das funktioniert nicht. Wenn man p drückt, greifen die Hotkeys immer noch.
02/22/2011 16:42 .SaFe#17
hmm dann habich ka... ich könnte dir ne dll basteln aber das mir für dafür zu umständlich sry
02/22/2011 18:22 P-a-i-n#18
Also wenn ich das richtig verstanden habe willst du mit einem Hotkey einen anderen Steuern, mach es so.

PHP Code:
    Dim NUM0 As Int32 = &H60
    Dim NUM1 
As Int32 = &H61
    Dim start1 
As Boolean = False


    
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Short

    
Public Function mHotkeys()

        If 
GetAsyncKeyState(NUM1) Then
            start1 
= True
        
Else
            
Label1.Text = "Num0 losgelassen"
            
start1 = False
        End 
If

        If 
start1 = True Then
            GetAsyncKeyState
(NUM0)
            
Label1.Text = "Num0 gedrückt"
        
End If

        Return 
Nothing
    End 
Function


    Private 
Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        mHotkeys
()
    
End Sub

    
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1
.Start()
        
Timer1.Interval = 50
    End Sub 
02/25/2011 11:59 Feuerkerk#19
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?