Hi!

I?m very new to Visual Basic, and I?m trying to accomplish something that seems quite difficult for me.
I want to make a script so that when I press the ?A? key briefly, it behaves normally, but if I hold down the A key for more than 300 ms, it should act as if I am holding the ?B? key instead (for as long as A is pressed).

So far, I haven?t gotten a good result, so I?ll just show where I started, hoping that someone more experienced can help me. Thanks!

Code:
Imports System.Runtime.InteropServices
Module Module1
    Private Const WH_KEYBOARD_LL As Integer = 13
    Private Const WM_KEYDOWN As Integer = &H100
    Private Const WM_KEYUP As Integer = &H101
    Private Const WM_SYSKEYDOWN As Integer = &H104
    Private Const WM_SYSKEYUP As Integer = &H105

    Private Delegate Function LowLevelKeyboardProc(nCode As Integer, wParam As IntPtr, lParam As IntPtr) As IntPtr
    Private hookID As IntPtr = IntPtr.Zero

    <DllImport("user32.dll")>
    Private Function SetWindowsHookEx(idHook As Integer, lpfn As LowLevelKeyboardProc, hMod As IntPtr, dwThreadId As UInteger) As IntPtr
    End Function

    <DllImport("user32.dll")>
    Private Function CallNextHookEx(hhk As IntPtr, nCode As Integer, wParam As IntPtr, lParam As IntPtr) As IntPtr
    End Function

    <DllImport("user32.dll")>
    Private Function UnhookWindowsHookEx(hhk As IntPtr) As Boolean
    End Function

    <DllImport("kernel32.dll")>
    Private Function GetModuleHandle(lpModuleName As String) As IntPtr
    End Function

    <DllImport("user32.dll")>
    Private Sub keybd_event(bVk As Byte, bScan As Byte, dwFlags As Integer, dwExtraInfo As Integer)
    End Sub

    Sub Main()
        hookID = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf HookCallback, GetModuleHandle(Nothing), 0)
        Windows.Forms.Application.Run()
        UnhookWindowsHookEx(hookID)
    End Sub

    Private Function HookCallback(nCode As Integer, wParam As IntPtr, lParam As IntPtr) As IntPtr
        If nCode >= 0 Then
            Dim vkCode As Integer = Marshal.ReadInt32(lParam)

            If vkCode = &H41 Then ' A key
                If wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN Then
                    keybd_event(&H42, 0, 0, 0) ' B down
                    Return New IntPtr(1) ' Block A down
                ElseIf wParam = WM_KEYUP Or wParam = WM_SYSKEYUP Then
                    keybd_event(&H42, 0, 2, 0) ' B up
                    Return New IntPtr(1) ' Block A up
                End If
            End If
        End If

        Return CallNextHookEx(hookID, nCode, wParam, lParam)
    End Function
End Module