2019年新出的一款免费游戏Apex,很火;然后看到有类似与CF那样切换武器可以实现子弹自动上膛的官方bug,所以有想法写一个辅助工具(捍卫者单喷变连喷)现在是已经完成了,测试也很OK。所以,写个文档记录一下。关于Hook的介绍就不说了。我的资源有现成的程序。
1. 要有一个DLL的Hook(全局),需要键盘钩子、鼠标钩子。
2.通过调用windows系统的SetWindowsHookEx函数来注入钩子
3.不需要钩子的时候,使用UnHookWindowsHookEx释放钩子
DLL的代码(3个文件):
1. HKTest.DPR
library HKTest;
uses
HKProc in 'HKProc.pas',
uMyThread in 'uMyThread.pas';
exports
EnableHotKeyHook,
DisableHotKeyHook;
begin
hNextHookProc:=0;
hMouseHookProc:=0;
procSaveExit:=ExitProc;
end.
2.HKProc.pas
unit HKProc;
interface
uses
Windows, Messages ;
var
hNextHookProc:HHook;
hMouseHookProc:HHook;
procSaveExit:Pointer;
g_iInterval1, g_iInterval2, g_iInterval3: integer; //换弹间隔,收起武器间隔,切换武器2 间隔
function KeyboardHookHandler(iCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;export;
function EnableHotKeyHook(iInterval1, iInterval2, iInterval3: integer):BOOL;export;
function DisableHotKeyHook:BOOL;export;
function MouseHookHandler(iCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;export;
function EnableMouseHook:BOOL;export;
function DisableMouseHook:BOOL;export;
procedure HotKeyHookExit;far;
implementation
uses
uMyThread;
function KeyboardHookHandler(iCode:integer;wParam:WPARAM;lParam:LPARAM):LRESULT;stdcall;export;
const _KeyPressMask = $80000000;
begin
Result:=0;
if iCode<0 then
begin
Result:= CallNextH