我需要以下密钥的密钥代码,实际上我想对记录器进行限制
1 ctrl
2 alt
3空间
4个粘滞键,例如家和终端等
5个功能键,如F1 - F12
6 Capslock,scroll,numlock,windows
7点,:,/,\,} {,[] | 〜,``
提示:其实我只想在我的APP空格键中使用A-Z,0-9和特殊字符
这个例子是js
if ((vkCode > 48 && vkCode < 91) || (vkCode > 93 && vkCode < 112) || (vkCode > 145) || (vkCode == 32))
{
}
还告诉我,当我按下数字键时,它会给D赋值 对于eaxmple
按4 --- D4
按9 - D9
答案 0 :(得分:2)
这是人们的需要
(Keys)vkCode
A-Z
(Keys)vkCode >= Keys.A && (Keys)vkCode <= Keys.Z)
TOP NUM 0-9
(vkCode <= 57 && vkCode >= 48)
NUMPAD NUM
(vkCode <= 105 && vkCode >= 96)
SPACE
(vkCode == 32)
输入
(vkCode == 13)
答案 1 :(得分:0)
.Net框架中的枚举列出了所有密钥,请参阅Keys
如果您正在处理Key事件,那么它将使用KeyEventArgs
这将为您提供键盘上活动的完整细分
private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
// Initialize the flag to false.
nonNumberEntered = false;
// Determine whether the keystroke is a number from the top of the keyboard.
if (e.KeyCode < Keys.D0 || e.KeyCode > Keys.D9)
{
// Determine whether the keystroke is a number from the keypad.
if (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9)
{
// Determine whether the keystroke is a backspace.
if(e.KeyCode != Keys.Back)
{
// A non-numerical keystroke was pressed.
// Set the flag to true and evaluate in KeyPress event.
nonNumberEntered = true;
}
}
}
//If shift key was pressed, it's not a number.
if (Control.ModifierKeys == Keys.Shift) {
nonNumberEntered = true;
}
}