• 大小: 164KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-13
  • 语言: 其他
  • 标签: HOOK  键盘  鼠标  窗体  

资源简介

最详尽的HooK钩子的使用例子,有各种钩子的使用方法,扑捉键盘和鼠标的动作之后,信息传递给窗体,在窗体中显示出完整的键盘操作履历

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsHook
{
public partial class Form1 : Form

        public static Form1 form1;
public Form1()
{
InitializeComponent();

            CheckForIllegalCrossThreadCalls = false;
            form1 = this;
}

KeyBordHook kbh = new KeyBordHook();
MouseHook mh = new MouseHook();

private void button1_Click(object sender EventArgs e)
{
mh.Start();
mh.OnMouseActivity += new MouseEventHandler(mh_OnMouseActivity);

kbh.Start();
            kbh.onkeydownEvent += new KeyEventHandler(kbh_onkeydownEvent);
kbh.onkeypressEvent += new KeyPressEventHandler(kbh_onkeypressEvent);
}

void mh_OnMouseActivity(object sender MouseEventArgs e)
{
this.label3.Text = “OnMouseActivity: “ + e.Button.ToString() + e.Location.ToString();
           
}

void kbh_onkeypressEvent(object sender KeyPressEventArgs e)
{
this.label1.Text = “onkeypressEvent: “ + e.KeyChar.ToString();

}
                                                                                                                 
void kbh_onkeydownEvent(object sender KeyEventArgs e)
{
this.label2.Text = “onkeydownEvent: “ + e.KeyValue.ToString();
            int index = this.dataGridView1.Rows.Add();
            this.dataGridView1.Rows[index].Cells[0].Value = System.DateTime.Now;
            this.dataGridView1.Rows[index].Cells[1].Value = ““;
            this.dataGridView1.Rows[index].Cells[2].Value = e.KeyCode.ToString();
            this.dataGridView1.Rows[index].Cells[3].Value = “X“;
            this.dataGridView1.Rows[index].Cells[4].Value = “X“;
            this.dataGridView1.Rows[index].Cells[5].Value = “X“;
            this.dataGridView1.CurrentCell = this.dataGridView1.Rows[index].Cells[0];

}

private void button3_Click(object sender EventArgs e)
{

            mh.OnMouseActivity -= new MouseEventHandler(mh_OnMouseActivity);
            kbh.onkeydownEvent -= new KeyEventHandler(kbh_onkeydownEvent);
            kbh.onkeypressEvent -= new KeyPressEventHandler(kbh_onkeypressEvent);
 kbh.Stop();
 mh.Stop();

             this.dataGridView1.Rows.Clear();

}
        private void dataGridView1_CellContentClick_1(object sender DataGridViewCellEventArgs e)
        {

        }

        public void drawShift() {
            this.dataGridView1.Rows[this.dataGridView1.RowCount-2].Cells[3].Value = “O“;
            this.dataGridView1.Rows[this.dataGridView1.RowCount-2].Cells[4].Value = “X“;
            this.dataGridView1.Rows[this.dataGridView1.RowCount-2].Cells[5].Value = “X“;
        }
        public void drawCtrl()
        {
            this.dataGridView1.Rows[this.dataGridView1.RowCount - 2].Cells[3].Value = “X“;
            this.dataGridView1.Rows[this.dataGridView1.RowCount - 2].C

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-03-27 15:38  WindowsHook\
     目录           0  2019-03-27 15:38  WindowsHook\Backup\
     文件        1241  2009-06-06 08:39  WindowsHook\Backup\Form1.cs
     文件        3469  2009-06-06 08:39  WindowsHook\Backup\Form1.Designer.cs
     文件        5814  2009-06-06 08:39  WindowsHook\Backup\Form1.resx
     文件        9624  2009-06-06 08:34  WindowsHook\Backup\KeyBordHook.cs
     文件        9010  2009-06-06 08:23  WindowsHook\Backup\MouseHook.cs
     文件         395  2009-06-05 13:26  WindowsHook\Backup\Program.cs
     目录           0  2019-03-18 14:39  WindowsHook\Backup\Properties\
     文件        3311  2009-06-06 08:40  WindowsHook\Backup\WindowsHook.csproj
     文件         910  2009-06-05 13:26  WindowsHook\Backup\WindowsHook.sln
     文件       15872  2009-06-06 08:40  WindowsHook\Backup\WindowsHook.v11.suo
     目录           0  2019-03-27 15:38  WindowsHook\bin\
     目录           0  2019-03-27 15:38  WindowsHook\bin\Debug\
     文件       33792  2019-03-20 19:58  WindowsHook\bin\Debug\WindowsHook.exe
     文件       52736  2019-03-20 19:58  WindowsHook\bin\Debug\WindowsHook.pdb
     文件       21464  2019-03-26 09:19  WindowsHook\bin\Debug\WindowsHook.vshost.exe
     文件         490  2013-06-18 20:28  WindowsHook\bin\Debug\WindowsHook.vshost.exe.manifest
     目录           0  2019-03-27 15:38  WindowsHook\bin\Release\
     文件       15872  2019-03-18 18:35  WindowsHook\bin\Release\WindowsHook.exe
     文件       32256  2019-03-18 18:35  WindowsHook\bin\Release\WindowsHook.pdb
     文件       21464  2019-03-18 18:35  WindowsHook\bin\Release\WindowsHook.vshost.exe
     文件         490  2013-06-18 20:28  WindowsHook\bin\Release\WindowsHook.vshost.exe.manifest
     文件        3629  2019-03-20 19:58  WindowsHook\Form1.cs
     文件        7439  2019-03-20 08:40  WindowsHook\Form1.Designer.cs
     文件        6918  2019-03-20 08:40  WindowsHook\Form1.resx
     文件       12800  2019-03-19 09:49  WindowsHook\KeyBordHook.cs
     文件        8692  2019-03-19 09:43  WindowsHook\MouseHook.cs
     目录           0  2019-03-27 15:38  WindowsHook\obj\
     目录           0  2019-03-27 15:38  WindowsHook\obj\Debug\
     文件        1229  2019-03-18 16:51  WindowsHook\obj\Debug\DesignTimeResolveAssemblyReferences.cache
............此处省略35个文件信息

评论

共有 条评论