求教热键设置涉及小键盘的数字键问题
小白一枚,后面跟我的代码,如何让按下含有Shift功能键时 再按小键盘数字键时过滤掉,不输入内容!或者有完整的由用户自定义全局热键代码也可以。
代码写的不好,只会if结构,见笑了!
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace HotKey
{
public partial class Form1 : Form
{
int modifiers;
Keys key;
public Form1()
{
InitializeComponent();
}
public static string GetString(Keys key)
{
//if (key == Keys.Delete || key == Keys.Insert || key == Keys.End || key == Keys.Down || key == Keys.PageDown || key == Keys.Left || key == Keys.Clear || key == Keys.Right || key == Keys.Home || key == Keys.Up || key == Keys.PageUp)
//{
// return "";
//}
if (key == Keys.None || key == Keys.Alt || key == Keys.Menu || key == Keys.Control || key == Keys.ControlKey || key == Keys.Shift || key == Keys.ShiftKey)
{
return "";
}
if (key == Keys.Oemtilde)
{
return "~";
}
string str = key.ToString();
return str;
}
public int GetInt32(Keys key)
{
if (key == Keys.Alt || key == Keys.Menu)
{
return 1;
}
else if (key == Keys.Control)
{
return 2;
}
else if (key == (Keys.Control | Keys.Alt))
{
return 3;
}
else if (key == Keys.Shift)
{
return 4;
}
else if (key == (Keys.Shift | Keys.Alt))
{
return 5;
}
else if (key == (Keys.Shift | Keys.Control))
{
return 6;
}
else if (key == (Keys.Shift | Keys.Control | Keys.Alt))
{
return 7;
}
return 0;
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
int i = textBox1.TabIndex;
string str;
modifiers = GetInt32(e.Modifiers);
if (modifiers == 0) { textBox1.Text = ""; } else { str = e.Modifiers.ToString(); str = str.ToString().Replace(",", " +"); textBox1.Text = str + " + "; }
str = GetString(e.KeyCode);
if (str == "")
{
key = Keys.None;
}
else
{
key = e.KeyCode;
textBox1.Text += str;
}
}
}
}