HOOK使用 全域性鍵盤鉤子

2021-06-04 11:07:28 字數 1331 閱讀 8031

//#define _win32_winnt 0x0500 //設定系統版本,可以使用底層鍵盤鉤子

#define wm_my_shorts (wm_user + 105)

#include "windows.h"

//全域性變數

lpword g_lpdwvirtualkey = null; //keycode 陣列的指標

int g_nlength = 0; //keycode 陣列的大小

hinstance g_hinstance = null; //模組例項控制代碼

hhook g_hhook = null; //鉤子控制代碼

hwnd g_hwnd = null;

bool apientry dllmain(handle hmodule, dword ul_reason_for_call,lpvoid lpreserved)

return true;

} lresult callback lowlevelkeyboardproc(int ncode, wparam wparam,lparam lparam)

//傳給系統中的下乙個鉤子

return callnexthookex(g_hhook, ncode, wparam, lparam);

} _declspec(dllexport)

bool winapi startcatch(lpword lpdwvirtualkey, int nlength, hwnd pwnd)

g_nlength = nlength;

//安裝底層鍵盤鉤子

g_hhook = setwindowshookex(wh_keyboard_ll, lowlevelkeyboardproc, g_hinstance, null);

if (g_hhook == null) return false;

return true;

} _declspec(dllexport)

bool winapi stopcatch()

利用底層的鍵盤鉤子

lresult callback lowlevelkeyboardproc(int ncode, wparam wparam,lparam lparam)

來攔截 按鍵的時候

鍵盤的鍵按下和彈起時候會發生wm_keyup 和 wm_keydown兩個訊息,

這兩個訊息都會被hook,所以如此。

所以需要對 wparam 進行判斷  是 wm_keydown 還是 wm_keyup

Hook技術 全域性鉤子

hook.cpp include stdafx.h include hook.h include hinstance g hinst const int keypres ask 0x80000000 鍵盤掩碼常量 char g prvchar pragma data seg shared stati...

VC全域性鍵盤鉤子

hodll.h main header file for the hodll dll if defined afx hodll h b2a458dc 71e2 47d5 9ea0 58385d558643 included define afx hodll h b2a458dc 71e2 47d5 ...

c 全域性鍵盤鉤子

using system using system.collections.generic using system.text using system.windows.forms using system.runtime.interopservices using system.diagnosti...