#include<windows.h>#include"SysHook.h"#include<jni.h>HINSTANCEhInst=NULL;JavaVM*jvm=NULL;jobjecthookObj_kb=NULL;jobjecthookObj_ms=NULL;jobjectg_kl=NULL;jmethodIDprocessKeyID_kb=NULL;jmethodIDprocessKeyID_ms=NULL;DWORDhookThreadId=0;LONGg_mouseLocX=-1;//x-locationofmousepositionLONGg_mouseLocY=-1;//y-locationofmousepositionextern"C"BOOLAPIENTRYDllMain(HINSTANCE_hInst,DWORDreason,LPVOIDreserved){switch(reason){caseDLL_PROCESS_ATTACH:printf("C++:DllMain-DLL_PROCESS_ATTACH.\n");hInst=_hInst;break;default:break;}returnTRUE;}LRESULTCALLBACKMouseTracker(intnCode,WPARAMwParam,LPARAMlParam){JNIEnv*env;KBDLLHOOKSTRUCT*p=(KBDLLHOOKSTRUCT*)lParam;if(jvm->AttachCurrentThread((void**)env,NULL)>=0){if(nCode==HC_ACTION){MOUSEHOOKSTRUCT*pStruct=(MOUSEHOOKSTRUCT*)lParam;if(pStruct->pt.x!=g_mouseLocX||pStruct->pt.y!=g_mouseLocY){env->CallVoidMethod(hookObj_ms,processKeyID_ms,(激nt)pStruct->pt.x,(激nt)pStruct->pt.y,g_kl);g_mouseLocX=pStruct->pt.x;g_mouseLocY=pStruct->pt.y;---本文来源于网络,仅供参考,勿照抄,如有侵权请联系删除---}}}else{printf("C++:LowLevelKeyboardProc-Errorontheattachcurrentthread.\n");}returnCallNextHookEx(NULL,nCode,wParam,lParam);}LRESULTCALLBACKLowLevelKeyboardProc(intnCode,WPARAMwParam,LPARAMlParam){JNIEnv*env;KBDLLHOOKSTRUCT*p=(KBDLLHOOKSTRUCT*)lParam;if(jvm->AttachCurrentThread((void**)env,NULL)>=0){switch(wParam){caseWM_KEYDOWN:caseWM_SYSKEYDOWN:env->CallVoidMethod(hookObj_kb,processKeyID_kb,(jboolean)TRUE,p->vkCode,g_kl);break;caseWM_KEYUP:caseWM_SYSKEYUP:env->CallVoidMethod(hookObj_kb,processKeyID_kb,(jboolean)FALSE,p->vkCode,g_kl);break;default:break;}}else{printf("C++:LowLevelKeyboardProc-Errorontheattachcurrentthread.\n");}returnCallNextHookEx(NULL,nCode,wParam,lParam);}voidMsgLoop(){MSGmessage;while(GetMessage(message,NULL,0,0))---本文来源于网络,仅供参考,勿照抄,如有侵权请联系删除---{TranslateMessage(message);DispatchMessage(message);}}JNIEXPORTvoidJNICALLJava_SysHook_registerHook(JNIEnv*env,jobjectobj,jobjectkl){HHOOKhookHandle_ms=SetWindowsHookEx(WH_MOUSE_LL,MouseTracker,hInst,0);HHOOKhookHandle_kb=SetWindowsHookEx(WH_KEYBOARD_LL,LowLevelKeyboardProc,hInst,0);g_kl=kl;if(hookHandle_ms==NULL){printf("C++:Java_SysHook_registerKeyHook-Hookfailed!\n");return;}else{printf("C++:Java_SysHook_registerKeyHook-Hooksuccessful\n");}if(hookHandle_kb==NULL){printf("C++:Java_SysHook_registerKeyHook-Hookfailed!\n");return;}else{printf("C++:Java_SysHook_registerKeyHook-Hooksuccessful\n");}hookObj_kb=env->NewGlobalRef(obj);jclasscls_kb=env->GetObjectClass(hookObj_kb);processKeyID_kb=env->GetMethodID(cls_kb,"processKey","(ZILGlobalEventListener;)V");hookObj_ms=env->NewGlobalRef(obj);jclasscls_ms=env->GetObjectClass(hookObj_ms);processKeyID_ms=env->GetMethodID(cls_ms,"mouseMoved","(IILGlobalEventListener;)V");env->GetJavaVM(jvm);hookThreadId=GetCurrentThreadId();MsgLoop();---本文来源于网络,仅供参考,勿照抄,如有侵权请联系删除---if(!UnhookWindowsHookEx(hookHandle_kb)){printf("C++:Java_SysHook_registerKeyHook-Unhookfailed\n");}else{printf("C++:Java_SysHook_registerKeyHook-Unhooksuccessful\n");}if(!UnhookWindowsHookEx(hookHandle_ms)){printf("C++:Java_SysHook_registerKeyHook-Unhookfailed\n");}else{printf("C++:Java_SysHook_registerKeyHook-Unhooksuccessful\n");}}JNIEXPORTvoidJNICALLJava_SysHook_unRegisterHook(JNIEnv*env,jobjectobjec...