91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 55KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2021-05-21
  • 語言: C#
  • 標簽: c#??Api??鉤子??demo??

資源簡介

c# SetWindowsHookEx 鉤子 demo

資源截圖

代碼片段和文件信息

using?System;
using?System.Diagnostics;
using?System.Runtime.InteropServices;
using?System.Threading;
using?System.Windows.Forms;

namespace?demo
{
????public?partial?class?Index?:?Form
????{

????????public?Index()
????????{
????????????InitializeComponent();
????????}

????????#region?API
????????[DllImport(“kernel32.dll“)]
????????private?static?extern?IntPtr?GetModuleHandle(string?name);

????????//建立鍵盤鉤子
????????[DllImport(“user32.dll“?CharSet?=?CharSet.Auto?CallingConvention?=?CallingConvention.StdCall)]
????????private?static?extern?int?SetWindowsHookEx(int?idHook?HookProc?lpfn?IntPtr?hInstance?int?threadId);

????????//移除鍵盤鉤子
????????[DllImport(“user32.dll“?CharSet?=?CharSet.Auto?CallingConvention?=?CallingConvention.StdCall)]
????????private?static?extern?bool?UnhookWindowsHookEx(int?idHook);

????????//把擊鍵信息傳遞到下一個監聽鍵盤事件的應用程序
????????[DllImport(“user32.dll“?CharSet?=?CharSet.Auto?CallingConvention?=?CallingConvention.StdCall)]
????????private?static?extern?int?CallNextHookEx(int?idHook?int?nCode?IntPtr?wParam?IntPtr?lParam);
????????#endregion

????????#region?變量
????????//標示
????????int?i?=?0;
????????//回調委托
????????private?delegate?int?HookProc(int?nCode?IntPtr?wParam?IntPtr?lParam);
????????//鉤子
????????int?idHook?=?0;
????????//是否安裝了鉤子
????????bool?isHook?=?false;
????????//鎖
????????private?static?readonly?object?obj?=?new?object();
????????GCHandle?gc;
????????private?const?int?WH_KEYBOARD_LL?=?13;??????//鉤子類型?全局鉤子
????????private?const?int?WM_KEYUP?=?0x101;?????//按鍵抬起
????????private?const?int?WM_KEYDOWN?=?0x100;???????//按鍵按下
????????#endregion

????????#region?安裝鉤子
????????private?void?Index_Load(object?sender?EventArgs?e)
????????{
????????????Msg(“開始運行“);
????????????//安裝鉤子
????????????{
????????????????//鉤子委托
????????????????HookProc?lpfn?=?new?HookProc(Hook);
????????????????//關聯進程的主模塊
????????????????IntPtr?hInstance?=?GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName);
????????????????//hInstance?=?Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]);
????????????????idHook?=?SetWindowsHookEx(WH_KEYBOARD_LL?lpfn?hInstance?0);
????????????????if?(idHook?>?0)
????????????????{
????????????????????Msg(“鉤子[“?+?idHook?+?“]安裝成功“);
????????????????????isHook?=?true;
????????????????????//保持活動?避免?回調過程?被垃圾回收
????????????????????gc?=?GCHandle.Alloc(lpfn);
????????????????}
????????????????else
????????????????{
????????????????????Msg(“鉤子安裝失敗“);
????????????????????isHook?=?false;
????????????????????UnhookWindowsHookEx(idHook);
????????????????}
????????????}
????????}
????????#endregion

????????#region?卸載鉤子
????????private?void?Index_FormClosing(object?sender?FormClosingEventArgs?e)
????????{
????????????//卸載鉤子
????????????if?(isHook)
????????????{
????????????????UnhookWindowsHookEx(idHook);
????????????}
????????}
????????#endregion

????????#region?鉤子回調
????????private?int?Hook(int?nCode

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2014-06-19?13:22??demo\
?????目錄???????????0??2014-06-19?13:59??demo\demo\
?????文件?????????902??2014-06-19?13:22??demo\demo.sln
?????文件???????34304??2014-06-19?16:18??demo\demo.v11.suo
?????目錄???????????0??2014-06-19?13:35??demo\demo\bin\
?????目錄???????????0??2014-06-19?13:36??demo\demo\bin\Debug\
?????文件???????11776??2014-06-19?16:11??demo\demo\bin\Debug\demo.exe
?????文件???????26112??2014-06-19?16:11??demo\demo\bin\Debug\demo.pdb
?????文件???????22472??2014-06-19?16:15??demo\demo\bin\Debug\demo.vshost.exe
?????目錄???????????0??2014-06-19?13:35??demo\demo\bin\Release\
?????文件????????3721??2014-06-19?14:35??demo\demo\demo.csproj
?????文件????????4880??2014-06-19?16:15??demo\demo\Index.cs
?????文件????????3413??2014-06-19?15:54??demo\demo\Index.Designer.cs
?????文件????????5817??2014-06-19?15:54??demo\demo\Index.resx
?????目錄???????????0??2014-06-19?13:22??demo\demo\obj\
?????目錄???????????0??2014-06-19?16:11??demo\demo\obj\Debug\
?????文件?????????522??2014-06-19?16:15??demo\demo\obj\Debug\demo.csproj.FileListAbsolute.txt
?????文件????????1033??2014-06-19?15:54??demo\demo\obj\Debug\demo.csproj.GenerateResource.Cache
?????文件????????2209??2014-06-19?13:25??demo\demo\obj\Debug\demo.csprojResolveAssemblyReference.cache
?????文件???????11776??2014-06-19?16:11??demo\demo\obj\Debug\demo.exe
?????文件?????????180??2014-06-19?15:54??demo\demo\obj\Debug\demo.Index.resources
?????文件???????26112??2014-06-19?16:11??demo\demo\obj\Debug\demo.pdb
?????文件?????????180??2014-06-19?14:35??demo\demo\obj\Debug\demo.Properties.Resources.resources
?????文件?????????863??2014-06-19?13:22??demo\demo\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件????????6785??2014-06-19?13:59??demo\demo\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????目錄???????????0??2014-06-19?13:22??demo\demo\obj\Debug\TempPE\
?????文件?????????485??2014-06-19?15:29??demo\demo\Program.cs
?????目錄???????????0??2014-06-19?13:22??demo\demo\Properties\
?????文件????????1346??2014-06-19?13:22??demo\demo\Properties\AssemblyInfo.cs
?????文件????????2860??2014-06-19?13:22??demo\demo\Properties\Resources.Designer.cs
?????文件????????5612??2014-06-19?13:22??demo\demo\Properties\Resources.resx
............此處省略2個文件信息

評論

共有 條評論