當程序不在激活的情況下,如何捕獲當前敲擊的鍵盤值並將其保存,而且不影響,當前運行的程序。 haha, 你不是要做木马吧?用系统钩子。不过XP下可能不行呀。你可以到安全技术论坛搜索以下。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1、用VC做个全局DLL的钩子,代码如下:KEYHOOK.C#include <windows.h>#include <windowsx.h>#include <tchar.h>HINSTANCE g_hinstDll = NULL;#pragma data_seg(".drectve") static char szLinkDirectiveShared[] = "-section:Shared,rws";#pragma data_seg()#pragma data_seg("Shared")HHOOK g_hhook = NULL;HWND g_hwndPost = NULL;UINT g_uMsgNotify = WM_USER;#pragma data_seg()static LRESULT WINAPI KeyboardHook_HookProc ( int nCode, WPARAM wParam, LPARAM lParam) { LRESULT lResult = CallNextHookEx(g_hhook, nCode, wParam, lParam); if (nCode == HC_ACTION) { PostMessage(g_hwndPost, g_uMsgNotify, wParam, lParam); } return(lResult);}BOOL WINAPI SetKeyboardHook (HWND hWndPost, UINT Msg) { HHOOK hhook; if (g_hhook != NULL) return(FALSE); g_hwndPost = hWndPost; g_uMsgNotify = Msg; Sleep(0); hhook = SetWindowsHookEx(WH_KEYBOARD, KeyboardHook_HookProc, g_hinstDll, 0); InterlockedExchange((PLONG) &g_hhook, (LONG) hhook); return(g_hhook != NULL);}BOOL WINAPI ReleaseKeyboardHook() { BOOL fOK = TRUE; if (g_hhook != NULL) { fOK = UnhookWindowsHookEx(g_hhook); g_hhook = NULL; } return(fOK);}BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved) { switch (fdwReason) { case DLL_PROCESS_ATTACH: g_hinstDll = hinstDll; break; } return(TRUE);}KEYHOOK.DEFEXPORTS SetKeyboardHook ReleaseKeyboardHook2、在VB中使用:Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As LongPublic Declare Function SetKeyboardHook Lib "KeybHook" (ByVal hwndPost As Long, ByVal Msg As Long) As LongPublic Declare Function ReleaseKeyboardHook Lib "KeybHook" () As Long VB对TXT的操作 还是个.NET问题,关于更改类属性 有关text文本框的设置,遇到一个小问题让我为难???请各位高手帮忙!!! MSFlexGrid有单元格内容满足要求后 有什么函数可以把一串字符串中间的空格去掉? vb+reportcreator 请教一个关于日期使用的问题 请问哪里有椭圆形按钮的控件或者源码?急用!!!在线等!!! 一个函数的问题! 关于用VB制作报表的问题 有vb项目的源代码,但不知道使用的控件名,请大家帮我看一下使用的是什么控件阿。急!! 怎样用VB在注册表中建立合法的DWORD值,我哪里错了?
KEYHOOK.C#include <windows.h>
#include <windowsx.h>
#include <tchar.h>HINSTANCE g_hinstDll = NULL;#pragma data_seg(".drectve")
static char szLinkDirectiveShared[] = "-section:Shared,rws";
#pragma data_seg()
#pragma data_seg("Shared")HHOOK g_hhook = NULL;
HWND g_hwndPost = NULL;
UINT g_uMsgNotify = WM_USER;#pragma data_seg()static LRESULT WINAPI KeyboardHook_HookProc (
int nCode,
WPARAM wParam,
LPARAM lParam)
{ LRESULT lResult = CallNextHookEx(g_hhook, nCode, wParam, lParam); if (nCode == HC_ACTION)
{
PostMessage(g_hwndPost, g_uMsgNotify, wParam, lParam);
}
return(lResult);
}BOOL WINAPI SetKeyboardHook (HWND hWndPost, UINT Msg)
{
HHOOK hhook; if (g_hhook != NULL) return(FALSE); g_hwndPost = hWndPost;
g_uMsgNotify = Msg;
Sleep(0); hhook = SetWindowsHookEx(WH_KEYBOARD, KeyboardHook_HookProc, g_hinstDll, 0);
InterlockedExchange((PLONG) &g_hhook, (LONG) hhook);
return(g_hhook != NULL);
}BOOL WINAPI ReleaseKeyboardHook()
{
BOOL fOK = TRUE; if (g_hhook != NULL)
{
fOK = UnhookWindowsHookEx(g_hhook);
g_hhook = NULL;
}
return(fOK);
}BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
g_hinstDll = hinstDll;
break;
}
return(TRUE);
}KEYHOOK.DEFEXPORTS
SetKeyboardHook
ReleaseKeyboardHook2、在VB中使用:
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SetKeyboardHook Lib "KeybHook" (ByVal hwndPost As Long, ByVal Msg As Long) As Long
Public Declare Function ReleaseKeyboardHook Lib "KeybHook" () As Long