请问各位大侠,键盘鼠标动作纪录与回放 ,如何控制回放速度呢?
源码如下:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
const MaxEventCount=1000 ;
EVENTMSG EventArr[MaxEventCount] ;
int EventLog,PlayLog,recOK,canPlay;
HHOOK hHook,hPlay;
bool bDelay;
//---------------------------------------------------------------------------
LRESULT __stdcall PlayProc(int iCode,WPARAM wParam, LPARAM lParam)
{
LRESULT Result=0;
canPlay=1;
if (iCode<0)
Result=CallNextHookEx(hPlay,iCode,wParam,lParam);
else if (iCode==HC_SYSMODALOFF)
canPlay=1;
else if (canPlay==1 && iCode==HC_GETNEXT)
{
if (bDelay)
{
bDelay=false;
Result=50; //
}
*((PEventMsg)lParam)=EventArr[PlayLog]; // pEventMsg(lParam)^:=EventArr[PlayLog];
}
else if (canPlay==1 && iCode==HC_SKIP)
{
bDelay=True;
PlayLog++;
}
if (PlayLog>=EventLog)
UnhookWindowsHookEx(hPlay);
return Result;
}
//---------------------------------------------------------------------------
LRESULT __stdcall HookProc(int iCode,WPARAM wParam, LPARAM lParam)
{
LRESULT Result=0;
recOK=1;
if (iCode<0)
Result=CallNextHookEx(hHook,iCode,wParam,lParam);
else if (iCode==HC_SYSMODALON)
recOK=0;
else if (iCode==HC_SYSMODALOFF)
recOK=1;
else if(recOK>0 && iCode==HC_ACTION)
{
EventArr[EventLog++]=*((PEventMsg)lParam); //EventArr[EventLog++]:=pEventMSG(lParam)^;
if (EventLog>=MaxEventCount)
UnhookWindowsHookEx(hHook);
}
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------
//录制
void __fastcall TForm1::Button1Click(TObject *Sender)
{
//建立键盘鼠标操作消息纪录链
EventLog=0;
hHook=SetWindowsHookEx(WH_JOURNALRECORD,(HOOKPROC)HookProc,HInstance,0);
Button2->Enabled=true;
Button3->Enabled=false;
}
//---------------------------------------------------------------------------
//暂停
void __fastcall TForm1::Button2Click(TObject *Sender)
{
UnhookWindowsHookEx(hHook);
hHook=NULL;
Button1->Enabled=true;
Button2->Enabled=false;
Button3->Enabled=true;
}
//---------------------------------------------------------------------------
//回放
void __fastcall TForm1::Button3Click(TObject *Sender)
{
//建立键盘鼠标操作消息纪录回放链
PlayLog=0;
hPlay=SetWindowsHookEx(WH_JOURNALPLAYBACK,(HOOKPROC)PlayProc,HInstance,0);
Button3->Enabled=false;
}