Click here to Skip to main content
15,881,413 members
Articles / Desktop Programming / Win32

Mirror keys for multiboxing MMORPG games like WOW/LOTRO

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
7 Mar 2013CPOL5 min read 20.5K   800   3  
Raw input 64-bit .NET classes.
Public Class UdpKeyPostManager
    Private m_keys As New Collections.Hashtable
    Private m_time As New Collections.Hashtable
    Public Sub AddPostMessage(ByVal WindowHandle As IntPtr, ByVal KeyInfo As UdpKeyInfo) ', ByVal message As UInteger, ByVal VKey As IntPtr, ByVal lparam As IntPtr)
        Dim idx As String = WindowHandle.ToString("X16") & "," & KeyInfo.Device.ToString("X16") & "," & KeyInfo.VKey.ToString("X4")
        If m_keys.Contains(idx) Then
            If m_keys(idx).GetType Is GetType(UdpKeyPost) Then
                Dim thisKeyPost As UdpKeyPost = DirectCast(m_keys(idx), UdpKeyPost)
                If thisKeyPost.IsFinished Then
                    Debug.WriteLine("finished")
                    m_keys.Remove(idx)
                Else
                    If (KeyInfo.Message And CUInt(1)) = 0 Then 'keydown
                        Debug.WriteLine("keydown update")
                        m_time.Remove(idx)
                        m_time.Add(idx, New DateTime(Now.Ticks))
                        RawInputHook.PostMessage(WindowHandle, KeyInfo.Message, New IntPtr(KeyInfo.VKey), New IntPtr(KeyInfo.lParam))
                    Else 'keyup
                        Debug.WriteLine("keyup natural                                            " & New IntPtr(KeyInfo.lParam).ToString("X16"))
                        thisKeyPost.Cancel()
                        RawInputHook.PostMessage(WindowHandle, KeyInfo.Message, New IntPtr(KeyInfo.VKey), New IntPtr(KeyInfo.lParam))
                        m_keys.Remove(idx)
                    End If
                End If
            Else
                m_keys.Remove(idx) 'value object type was not UdpKeyPost(?should never happen?)
            End If
        Else
            Debug.WriteLine("keydown new")
        End If
        If (((KeyInfo.Message And CUInt(1)) = 0) AndAlso (Not m_keys.Contains(idx))) Then
            If m_time.Contains(idx) Then m_time.Remove(idx)
            m_time.Add(idx, New DateTime(Now.Ticks))
            m_keys.Add(idx, New UdpKeyPost(Me, WindowHandle, KeyInfo))
        End If

    End Sub

    Public Function LastKeydown(ByVal WindowHandle As IntPtr, ByVal KeyInfo As UdpKeyInfo) As DateTime
        Dim result As New DateTime(0)
        Dim idx As String = WindowHandle.ToString("X16") & "," & KeyInfo.Device.ToString("X16") & "," & KeyInfo.VKey.ToString("X4")
        If m_time.Contains(idx) Then
            If m_time(idx).GetType Is GetType(DateTime) Then
                result = DirectCast(m_time(idx), DateTime)
            End If
        End If
        Return result
    End Function

    Public Sub Remove(ByVal idx As String)
        If m_keys.Contains(idx) Then
            m_keys.Remove(idx)
        End If
    End Sub

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions