找传奇、传世资源到传世资源站!

c++ 模拟鼠标按键

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

设定按键坐标与定时器,自动点击鼠标
from clipboard //---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit2.h"
#include <System.IniFiles.hpp>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFrame2 *Frame2;
//---------------------------------------------------------------------------
__fastcall TFrame2::TFrame2(TComponent* Owner)
: TFrame(Owner)
{
nMx = 0;
nMy = 0;
    nInterval = 10;
}
//---------------------------------------------------------------------------
void __fastcall TFrame2::FrameInit(int nIndex)
{
    box->Caption = String(nIndex);
this->Tag = nIndex;

TIniFile *IniFile = new TIniFile(ExtractFilePath(Application->ExeName) "config.ini");
String group;
group.sprintf(L"GROUP%d",nIndex);
if(IniFile){

Mx->Text = IniFile->ReadString(group,"MX","0");
My->Text = IniFile->ReadString(group,"MY","0");
chInterval->Checked = IniFile->ReadInteger(group,"BREP",0)==0?false:true;
txtIntval->Text = IniFile->ReadString(group,"INTERVAL","10");
delete IniFile;
}
    this->btnPause->Enabled = false;
}
void __fastcall TFrame2::btnSaveClick(TObject *Sender)
{
//
int nIndex = this->Tag;
    TIniFile *IniFile = new TIniFile(ExtractFilePath(Application->ExeName) "config.ini");
String group;
group.sprintf(L"GROUP%d",nIndex);
if(IniFile){

IniFile->WriteString(group,"MX",Mx->Text);
IniFile->WriteString(group,"MY",My->Text);
IniFile->WriteInteger(group,"BREP",chInterval->Checked?1:0);
nInterval = _wtoi(txtIntval->Text.c_str());
if(nInterval<1) nInterval =1;

IniFile->WriteString(group,"INTERVAL",nInterval);
delete IniFile;
if(Sender==btnSave){
ShowMessage("保存参数成功");
}
}

nMx = _wtoi(Mx->Text.c_str());
nMy = _wtoi(My->Text.c_str());
tm->Interval = nInterval*1000;

}
//---------------------------------------------------------------------------

void __fastcall TFrame2::btnStartClick(TObject *Sender)
{

    btnSaveClick(Sender);

if(btnStart->Tag==0){
btnStart->Tag = 1;
btnStart->Enabled = false;

tmTimer(tm);

if(chInterval->Checked){
tm->Enabled = true;
}
btnPause->Enabled = true;
}
}
//---------------------------------------------------------------------------

void __fastcall TFrame2::tmTimer(TObject *Sender)
{
//

SetCursorPos(nMx,nMy);//注意:这个坐标是屏幕的绝对坐标
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);

}
//---------------------------------------------------------------------------

void __fastcall TFrame2::btnPauseClick(TObject *Sender)
{
//
tm->Enabled = false;
btnStart->Tag = 0;
btnStart->Enabled = true;
btnPause->Enabled = false;}
//---------------------------------------------------------------------------

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复