public ScreenKeyboard() { InitializeComponent(); base.TopMost = true; base.StartPosition = FormStartPosition.CenterScreen; HandleClickEvents(this.Controls); this.hook = new HookEx.UserActivityHook(true, true); this.hook.MouseActivity += HookOnMouseActivity; }
protected override void Dispose(bool disposing) { if (disposing) { this.hook.Stop(); this.hook = null; if (components != null) { components.Dispose(); } } base.Dispose(disposing); }
private static IDictionary <short, IList <FecitButton> > combinationVKButtonsMap; //表示键/值对应的泛型集合 public Frm_Main() { InitializeComponent(); #region 将指定的按钮值添加到键类型中 spacialVKButtonsMap = new Dictionary <short, IList <FecitButton> >(); combinationVKButtonsMap = new Dictionary <short, IList <FecitButton> >(); IList <FecitButton> buttonList = new List <FecitButton>(); //实例化IList<FecitButton>(按照索引单独访问的一组对象) buttonList.Add(this.btnLCTRL); //添加左面的CTRL键 combinationVKButtonsMap.Add(KeyboardConstaint.VK_CONTROL, buttonList); //添加左面的CTRL键值 buttonList = new List <FecitButton>(); buttonList.Add(this.btnLSHFT); //添加左面的LSHFT键 buttonList.Add(this.btnRSHFT); //添加右面的LSHFT键 combinationVKButtonsMap.Add(KeyboardConstaint.VK_SHIFT, buttonList); //添加LSHFT键值 buttonList = new List <FecitButton>(); //实例化IList<FecitButton> buttonList.Add(this.btnLALT); //添加左面的ALT键 combinationVKButtonsMap.Add(KeyboardConstaint.VK_MENU, buttonList); //添加左面的ALT键值 buttonList = new List <FecitButton>(); //实例化IList<FecitButton> buttonList.Add(this.btnLW); //添加左面的WIN键 combinationVKButtonsMap.Add(KeyboardConstaint.VK_LWIN, buttonList); //添加左面的WIN键值 buttonList = new List <FecitButton>(); //实例化IList<FecitButton> buttonList.Add(this.btnLOCK); //添加LOCK键 spacialVKButtonsMap.Add(KeyboardConstaint.VK_CAPITAL, buttonList); //添加LOCK键值 #endregion foreach (Control ctrl in this.Controls) { FecitButton button = ctrl as FecitButton; if (button == null) { continue; } #region 设置按键的消息值 short key = 0;//记录键值 bool isSpacialKey = true; //记录快捷键的键值 switch (button.Name) //获取键名称 { case "btnLCTRL": //CTRL键的左键名称 case "btnRCTRL": //CTRL键的右键名称 key = KeyboardConstaint.VK_CONTROL; //获取CTRL键的键值 break; case "btnLSHFT": //SHFT键的左键名称 case "btnRSHFT": //SHFT键的左键名称 key = KeyboardConstaint.VK_SHIFT; //获取SHFT键的键值 break; case "btnLALT": //ALT键的左键名称 case "btnRALT": //ALT键的左键名称 key = KeyboardConstaint.VK_MENU; //获取ALT键的键值 break; case "btnLW": //WIN键的左键名称 case "btnRW": //WIN键的左键名称 key = KeyboardConstaint.VK_LWIN; //获取WIN键的键值 break; case "btnESC": //ESC键的名称 key = KeyboardConstaint.VK_ESCAPE; //获取ESC键的键值 break; case "btnTAB": //TAB键的名称 key = KeyboardConstaint.VK_TAB; //获取TAB键的键值 break; case "btnF1": //F1键的名称 key = KeyboardConstaint.VK_F1; //获取F1键的键值 break; case "btnF2": key = KeyboardConstaint.VK_F2; break; case "btnF3": key = KeyboardConstaint.VK_F3; break; case "btnF4": key = KeyboardConstaint.VK_F4; break; case "btnF5": key = KeyboardConstaint.VK_F5; break; case "btnF6": key = KeyboardConstaint.VK_F6; break; case "btnF7": key = KeyboardConstaint.VK_F7; break; case "btnF8": key = KeyboardConstaint.VK_F8; break; case "btnF9": key = KeyboardConstaint.VK_F9; break; case "btnF10": key = KeyboardConstaint.VK_F10; break; case "btnF11": key = KeyboardConstaint.VK_F11; break; case "btnF12": key = KeyboardConstaint.VK_F12; break; case "btnENT": case "btnNUMENT": key = KeyboardConstaint.VK_RETURN; break; case "btnWave": key = KeyboardConstaint.VK_OEM_3; break; case "btnSem": key = KeyboardConstaint.VK_OEM_1; break; case "btnQute": key = KeyboardConstaint.VK_OEM_7; break; case "btnSpace": key = KeyboardConstaint.VK_SPACE; break; case "btnBKSP": key = KeyboardConstaint.VK_BACK; break; case "btnComma": key = KeyboardConstaint.VK_OEM_COMMA; break; case "btnFullStop": key = KeyboardConstaint.VK_OEM_PERIOD; break; case "btnLOCK": key = KeyboardConstaint.VK_CAPITAL; break; case "btnMinus": key = KeyboardConstaint.VK_OEM_MINUS; break; case "btnEqual": key = KeyboardConstaint.VK_OEM_PLUS; break; case "btnLBracket": key = KeyboardConstaint.VK_OEM_4; break; case "btnRBracket": key = KeyboardConstaint.VK_OEM_6; break; case "btnPath": key = KeyboardConstaint.VK_OEM_5; break; case "btnDivide": key = KeyboardConstaint.VK_OEM_2; break; case "btnPSC": key = KeyboardConstaint.VK_SNAPSHOT; break; case "btnINS": //Insert键的名称 key = KeyboardConstaint.VK_INSERT; //获取Insert键的键值 break; case "btnDEL": //Delete键的名称 key = KeyboardConstaint.VK_DELETE; //获取Delete键的键值 break; default: isSpacialKey = false; break; } if (!isSpacialKey) { key = (short)button.Name[3]; //获取按钮的键值 } button.Tag = key; //在按钮的Tag属性中记录相应的键值 #endregion button.Click += ButtonOnClick; //重载按钮的单击事件 } this.hook = new HookEx.UserActivityHook(true, true); HookEvents(); }