|
Public Class UdpKeyBufferFILO
Private Const m_buffer_length_default As Integer = 4
Private m_buffer(m_buffer_length_default) As UdpKeyInfo
Public Sub New(Optional ByVal _length As Integer = m_buffer_length_default)
If _length <> m_buffer_length_default Then
If _length > 1 Then
ReDim m_buffer(_length - 1)
Else
_length = m_buffer_length_default
End If
End If
For i As Integer = 0 To _length - 1
m_buffer(i) = Nothing
Next
End Sub
Public Sub Push(ByVal KeyInfo As UdpKeyInfo)
If ((KeyInfo.Message And CUInt(1)) = 0) Then 'keydown - valid for pushes
Dim found As Boolean = False
For i As Integer = 0 To m_buffer.Length - 1
If ((Not m_buffer(i) Is Nothing) AndAlso (m_buffer(i).VKey = KeyInfo.VKey) AndAlso (m_buffer(i).Device = KeyInfo.Device)) Then
found = True
End If
Next
If Not found Then
For i As Integer = m_buffer.Length - 1 To 1 Step -1
m_buffer(i) = m_buffer(i - 1)
Next
m_buffer(0) = KeyInfo
End If
End If
End Sub
Public Function Pop(ByVal KeyInfo As UdpKeyInfo) As UdpKeyInfo
Dim result As UdpKeyInfo = Nothing
If ((KeyInfo.Message And CUInt(1)) = 1) Then 'keyup - valid for pops
For i As Integer = m_buffer.Length - 1 To 0 Step -1
If ((Not m_buffer(i) Is Nothing) AndAlso (m_buffer(i).VKey = KeyInfo.VKey) AndAlso (m_buffer(i).Device = KeyInfo.Device)) Then
result = m_buffer(i)
m_buffer(i) = Nothing
End If
Next
End If
Return result
End Function
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.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.