Exemple #1
0
        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();
            }
        }
Exemple #2
0
        private void metroTabControl_main_Selected(object sender, TabControlEventArgs e)
        {
            if (metroTabControl_main.SelectedTab == metroTabPage_chart)
            {
                PieChartExample();
                Timer.Start();
            }
            else
            {
                Timer.Stop();
            }
            if (metroTabControl_main.SelectedTab == metroTabPage_count)
            {
                //切换统计选项卡
                //var today = DateTime.Now.Date.AddDays(-1);
                var today = DateTime.Now.Date;
                using (var context = new WareHouse_localEntities())
                {
                    var L2EQuery = from km in context.KeyMice
                                   where km.ExecuteDate >= today
                                   group km by new { km.KeyData, km.DeviceName } into g
                    orderby g.Count() descending
                        select new { Peo = g.Key, Count = g.Count() };
                    var keyList   = L2EQuery.ToList();
                    var L2EQuery2 = context.KeyMice.Where(
                        s => s.ExecuteDate >= today
                        );
                    var L2EQuery3 = context.KeyMice;
                    var cont      = L2EQuery2.Count <KeyMouse>();
                    var cont2     = L2EQuery3.Count <KeyMouse>();
                    metroTile1.Text = string.Format("今天按了{0}次\n\r一共按了{1}次", cont.ToString(), cont2.ToString());

                    BindingList <KeyMouseModel> keyMs = new BindingList <KeyMouseModel>();
                    for (int i = 0; i < keyList.Count; i++)
                    {
                        KeyMouseModel keyM = new KeyMouseModel();
                        keyM.DeviceName    = keyList[i].Peo.DeviceName;
                        keyM.KeyData       = keyList[i].Peo.KeyData;
                        keyM.ExtendedValue = keyList[i].Count.ToString();
                        keyMs.Add(keyM);
                    }
                    this.metroGrid_count.DataSource = keyMs;
                };
            }
        }
Exemple #3
0
        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();
        }