|
public class UdpKeyBufferFILO
{
private const int m_buffer_length_default = 4;
private UdpKeyInfo[] m_buffer = new UdpKeyInfo[m_buffer_length_default + 1];
public UdpKeyBufferFILO(int _length)
{
if (_length != m_buffer_length_default) {
if (_length > 1) {
m_buffer = new UdpKeyInfo[_length + 1];
} else {
_length = m_buffer_length_default;
}
}
for (int i = 0; i <= _length - 1; i++) {
m_buffer[i] = null;
}
}
public void Push(UdpKeyInfo KeyInfo)
{
//keydown - valid for pushes
if (((KeyInfo.Message &System.Convert.ToUInt32(1)) == 0)) {
bool found = false;
for (int i = 0; i <= m_buffer.Length - 1; i++) {
if ((((m_buffer[i] != null)) && (m_buffer[i].VKey == KeyInfo.VKey) && (m_buffer[i].Device == KeyInfo.Device))) {
found = true;
}
}
if (!found) {
for (int i = m_buffer.Length - 1; i >= 1; i += -1) {
m_buffer[i] = m_buffer[i - 1];
}
m_buffer[0] = KeyInfo;
}
}
}
public UdpKeyInfo Pop(UdpKeyInfo KeyInfo)
{
UdpKeyInfo result = null;
//keyup - valid for pops
if (((KeyInfo.Message &System.Convert.ToUInt32(1)) == 1)) {
for (int i = m_buffer.Length - 1; i >= 0; i += -1) {
if ((((m_buffer[i] != null)) && (m_buffer[i].VKey == KeyInfo.VKey) && (m_buffer[i].Device == KeyInfo.Device))) {
result = m_buffer[i];
m_buffer[i] = null;
}
}
}
return result;
}
}
|
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.