|
public class UdpKeyPostManager
{
private System.Collections.Hashtable m_keys = new System.Collections.Hashtable();
private System.Collections.Hashtable m_time = new System.Collections.Hashtable();
public void AddPostMessage(System.IntPtr WindowHandle, UdpKeyInfo KeyInfo)
{
string idx = WindowHandle.ToString("X16") + "," + KeyInfo.Device.ToString("X16") + "," + KeyInfo.VKey.ToString("X4");
if (m_keys.Contains(idx)) {
if (typeof(UdpKeyPost).Equals(m_keys[idx].GetType()))
{
UdpKeyPost thisKeyPost = (UdpKeyPost)m_keys[idx];
if (thisKeyPost.IsFinished) {
System.Diagnostics.Debug.WriteLine("finished");
m_keys.Remove(idx);
} else {
//keydown
if ((KeyInfo.Message &System.Convert.ToUInt32(1)) == 0) {
System.Diagnostics.Debug.WriteLine("keydown update");
m_time.Remove(idx);
m_time.Add(idx, new System.DateTime(System.DateTime.Now.Ticks));
RawInputHook.PostMessage(WindowHandle, KeyInfo.Message, KeyInfo.VKey, KeyInfo.lParam);
//keyup
} else {
System.Diagnostics.Debug.WriteLine("keyup natural " + KeyInfo.lParam.ToString("X16"));
thisKeyPost.Cancel();
RawInputHook.PostMessage(WindowHandle, KeyInfo.Message, KeyInfo.VKey, KeyInfo.lParam);
m_keys.Remove(idx);
}
}
} else {
m_keys.Remove(idx);
//value object type was not UdpKeyPost(?should never happen?)
}
} else {
System.Diagnostics.Debug.WriteLine("keydown new");
}
if ((((KeyInfo.Message &System.Convert.ToUInt32(1)) == 0) && (!m_keys.Contains(idx)))) {
if (m_time.Contains(idx))
m_time.Remove(idx);
m_time.Add(idx, new System.DateTime(System.DateTime.Now.Ticks));
m_keys.Add(idx, new UdpKeyPost(this, WindowHandle, KeyInfo));
}
}
public System.DateTime LastKeydown(System.IntPtr WindowHandle, UdpKeyInfo KeyInfo)
{
System.DateTime result = new System.DateTime(0);
string idx = WindowHandle.ToString("X16") + "," + KeyInfo.Device.ToString("X16") + "," + KeyInfo.VKey.ToString("X4");
if (m_time.Contains(idx)) {
if (typeof(System.DateTime).Equals(m_time[idx].GetType()))
{
result = (System.DateTime)m_time[idx];
}
}
return result;
}
public void Remove(string idx)
{
if (m_keys.Contains(idx)) {
m_keys.Remove(idx);
}
}
}
|
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.