Esempio n. 1
0
 public static CSGlobal GetInstance()
 {
     if (instance == null)
     {
         instance = new CSGlobal();
     }
     return(instance);
 }
Esempio n. 2
0
        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            string str = GetExceptionMsg(e.ExceptionObject as Exception, e.ToString());

            CSGlobal.GetInstance().Log.Info(DateTime.Now.ToString() + ":系统错误\n" + str);
            MetroMessageBox.Show(CSGlobal.GetInstance().hookFrm,
                                 "发生了未经处理的非UI异常\n" + e.ToString().Split(new char[2] {
                '\n', '\r'
            })[0],
                                 "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Esempio n. 3
0
        static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            string str = GetExceptionMsg(e.Exception, e.ToString());

            CSGlobal.GetInstance().Log.Info(DateTime.Now.ToString() + ":系统错误\n" + str);
            MetroMessageBox.Show(CSGlobal.GetInstance().hookFrm,
                                 "发生了未经处理的UI异常\n" + e.ToString().Split(new char[2] {
                '\n', '\r'
            })[0],
                                 "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Esempio n. 4
0
 private void HookOutputFrm2_Load(object sender, EventArgs e)
 {
     // TODO: 这行代码将数据加载到表“wareHouse_localDataSet.KeyMouse”中。您可以根据需要移动或删除它。
     //this.keyMouseTableAdapter.Fill(this.wareHouse_localDataSet.KeyMouse);
     CSGlobal.GetInstance().k_hook.KeyDown += K_hook_KeyDown;     //全局按键事件
     CSGlobal.GetInstance().k_hook.KeyUp += K_hook_KeyUp;
     CSGlobal.GetInstance().k_hook.Start();                       //安装键盘钩子
     CSGlobal.GetInstance().m_hook.MouseDown += M_hook_MouseDown; //全局点击事件
     CSGlobal.GetInstance().m_hook.Start();
     this.metroGrid_kmData.DataSource = CSGlobal.GetInstance().KeyMs;
 }
Esempio n. 5
0
 private void K_hook_KeyUp(object sender, KeyEventArgs e)
 {
     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;
     }
 }
Esempio n. 6
0
 private void metroGrid_kmData_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
 {
     //保持datagrid100行,数据太多datagrid性能会变差
     if (CSGlobal.GetInstance().KeyMs.Count > 30)
     {
         CSGlobal.GetInstance().KeyMs.RemoveAt(0);
     }
     if (
         metroGrid_kmData.DataSource != null &&
         this.metroGrid_kmData.Rows.Count > 0 &&
         !this.metroGrid_kmData.Focused &&
         metroTabControl_main.SelectedTab == metroTabPage_log
         )
     {
         this.metroGrid_kmData.FirstDisplayedScrollingRowIndex = this.metroGrid_kmData.Rows.Count - 1;
     }
 }
Esempio n. 7
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();
            }
        }
Esempio n. 8
0
        //右键打开文件夹
        private void ToolStripMenuItem_open_Click(object sender, EventArgs e)
        {
            var selectRows = metroGrid_kmData.SelectedRows;

            if (selectRows.Count == 0)
            {
                return;
            }
            string filePath = selectRows[0].Cells["ProcessPath"].Value.ToString();

            try
            {
                if (!File.Exists(filePath) && !Directory.Exists(filePath))
                {
                    return;
                }
                if (Directory.Exists(filePath))
                {
                    Process.Start(@"explorer.exe", "/select,\"" + filePath + "\"");
                }
                else
                {
                    IntPtr pidlList = Common.Common.ILCreateFromPathW(filePath);
                    if (pidlList != IntPtr.Zero)
                    {
                        try
                        {
                            Marshal.ThrowExceptionForHR(Common.Common.SHOpenFolderAndSelectItems(pidlList, 0, IntPtr.Zero, 0));
                        }
                        finally
                        {
                            Common.Common.ILFree(pidlList);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MetroMessageBox.Show(CSGlobal.GetInstance().hookFrm, "打开文件夹失败\n" + ex.ToString(), "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 9
0
 static void Main()
 {
     try
     {
         //处理未捕获的异常
         Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
         //处理UI线程异常
         Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
         //处理非UI线程异常
         AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
         Process[] pro = Process.GetProcessesByName("KeyRecord");
         if (pro != null && pro.Length > 1)
         {
             DialogResult dir = MetroMessageBox.Show(CSGlobal.GetInstance().hookFrm, "已经有一个KeyRecord程序正在运行,是否继续?", "系统提示", MessageBoxButtons.YesNo);
             if (dir == DialogResult.No)
             {
                 Application.Exit();
                 return;
             }
         }
         log4net.Config.XmlConfigurator.Configure();
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         Application.Run(CSGlobal.GetInstance().hookFrm);
         //Application.Run(new HeatMapFrm());
     }
     catch (Exception ex)
     {
         string str = GetExceptionMsg(ex, string.Empty);
         CSGlobal.GetInstance().Log.Info(DateTime.Now.ToString() + ":系统错误\n" + str);
         MetroMessageBox.Show(CSGlobal.GetInstance().hookFrm,
                              "发生了未经处理的异常\n" + ex.ToString().Split(new char[2] {
             '\n', '\r'
         })[0],
                              "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Esempio n. 10
0
 private void metroButton4_Click(object sender, EventArgs e)
 {
     MetroMessageBox.Show(CSGlobal.GetInstance().hookFrm, "该功能还未实现", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
Esempio n. 11
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();
        }