C 簡單滑鼠鍵盤鉤子KMHook

2022-06-30 07:09:12 字數 2364 閱讀 5000

簡介:由三個檔案構成pinvo.cs、keyboardhook.cs、mousehook.cs

pinvo.cs 是keyboardhook與mousehook需要的一些常量訊息的定義

keyboardhook 是實現的乙個wh_keyboard_ll型別的全域性鍵盤鉤子(setwindowshookexa函式最後乙個引數threadid=0)

mousehook 是實現的乙個wh_mouse_ll型別的全域性滑鼠按鍵鉤子(setwindowshookexa函式最後乙個引數threadid=0)

pinvo

1

using

system;

2using

system.collections.generic;

3using

system.linq;

4using

system.text;

5using

system.threading.tasks;67

namespace

kmhook815

16public

class

messages

17310 }

keyboardhook

using

system;

using

system.runtime.interopservices;

namespace

kmhook

return

false

; }

}//////

vkcode 表示1到254間的虛擬鍵盤碼

///scancode 表示硬體掃瞄碼

///[structlayout(layoutkind.sequential)]

public

class

keydata

public

void

setuphook()

}private

void

removehook()

}private

int kmproc(int ncode, int

wparam, keydata lparam)

bool shouldblock = false

;

if (keyevent != null

)

if (wparam == messages.wm_keydown ||wparam ==messages.wm_syskeydown)

}if (wparam == messages.wm_keyup ||wparam ==messages.wm_syskeyup)

}if (!shouldblock)

return1;

}public

void

dispose()

}}

mousehook

using

system;

using

system.runtime.interopservices;

namespace

kmhook

[structlayout(layoutkind.sequential)]

public

class

mousedata

public

bool

ishooked

return

false

; }

}public

void

setuphook()

}private

void

removehook()

}private

int kmproc(int ncode, int

wparam, mousedata lparam)

bool shouldblock = false

;

if (mouseevent != null

)

if (!shouldblock)

return1;

}public

void

dispose()

}}

**使用情況

keyboardhook keyboardhook = new

keyboardhook();

keyboardhook.keyevent += (keydata, message) =>

return

true;};

keyboardhook.setuphook();

利用滑鼠鍵盤鉤子截獲密碼

利用滑鼠鍵盤鉤子截獲密碼。原始碼示例 http zeena.nease.net soft getpass src.rar 鉤子能截獲系統並得理髮送給其它應用程式的訊息,能完成一般程式無法完成的功能。掌握鉤子的程式設計方法是很有必要的 鉤子分類 1 wh callwndproc和wh callwndp...

通用滑鼠鍵盤

該程式通過並行機制處理滑鼠和鍵盤的訊息,為了簡化程式裁減了一些 該程式可用為基礎在該程式上新增 可用於文字編輯,遊戲和其他滑鼠鍵盤通用的程式.include include include include include union regs regs unsigned size void far ...

滑鼠鍵盤學習

出現問題地方 1 label 和pushbutton上面無法顯示中文,出現亂碼 待解決 在main.cpp中已加入qtext odec setcodecfortr qtextcodec codecforlocale 2 在鍵入兩個函式 void mousemoveevent qmouseevent ...