Mianowicie chciałbym aby w tym programie dało się dodawać akcje typu
keybd_event('A', 0, 0, 0);
keybd_event('A', 0, KEYEVENTF_KEYUP, 0);
Wiem ze potrzebna jest tablica, ale nie mam pomysłu jak to zrobić tutaj mam obecny kod
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <vector>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CSPIN"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
POINT cur;
std::vector<POINT> t_cur;
String poslist;
int p;
int powtorzenia=10-1;
void add_pose()
{
t_cur.push_back(cur);
poslist = " X: " +IntToStr(cur.x) + " Y: " + IntToStr(cur.y);
Form1->ListBox1->Items->Add(poslist);
}
void __fastcall TForm1::HotKey(TMessage &Msg)
{
if (Msg.WParam == 1){
Timer1->Enabled=false;
}
if (Msg.WParam == 2) {
add_pose();
}
if (Msg.WParam == 3) {
}
}
int obecne = 0;
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Timer1->Enabled = true;
Timer2->Enabled = true;
obecne = 0;
}
//---------------------------------------------------------------------------
void wykonaj()
{
//keybd_event('Z', 0, 0, 0);
//keybd_event('Z', 0, KEYEVENTF_KEYUP, 0);
if (p < t_cur.size())
{
if( Form1->ProgressBar1->Position < 100)
{
Form1->ProgressBar1->Position+=10;
}
else
{
Form1-> ProgressBar1->Position=0;
}
t_cur[p].x;
SetCursorPos(t_cur[p].x, t_cur[p].y);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
p++;
//keybd_event('Z', 0, 0, 0);
//keybd_event('Z', 0, KEYEVENTF_KEYUP, 0);
}
else
{
p = 0;
}
}
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Form1->Panel1->Color = RGB(rand()%250, rand()%250, rand()%250 );
if (obecne <= powtorzenia)
{
Form1->Label2->Caption=obecne+1;
if( Form1->ProgressBar1->Position < 100)
{
Form1->ProgressBar1->Position+=10;
}
else
{
Form1-> ProgressBar1->Position=0;
}
keybd_event('A', 0, 0, 0);
keybd_event('A', 0, KEYEVENTF_KEYUP, 0);
if (p < t_cur.size())
{
t_cur[p].x;
SetCursorPos(t_cur[p].x, t_cur[p].y);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
p++;
//keybd_event('Z', 0, 0, 0);
//keybd_event('Z', 0, KEYEVENTF_KEYUP, 0);
}
else
{
p = 0;
obecne++;
}
}
else
{
Timer1->Enabled=false;
}
// Form1->Timer1->Enabled=false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Timer1->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer2Timer(TObject *Sender)
{
cur.x = Mouse->CursorPos.x;
cur.y = Mouse->CursorPos.y;
// Mouse->CursorPos.x;
// Mouse->CursorPos.y;
Label1->Caption = "X: " + IntToStr(cur.x) + " Y: " + IntToStr(cur.y);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
add_pose();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
ListBox1->Clear();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
for (int i = 0; i < t_cur.size(); i++)
{
poslist = " X: " +IntToStr(t_cur[i].x) + " Y: " + IntToStr(t_cur[i].y);
Form1->ListBox1->Items->Add(poslist);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
RegisterHotKey(Form1->Handle, 1, 0, VK_SPACE);
RegisterHotKey(Form1->Handle, 2, 0, VK_TAB);
p=0;
}
//---------------------------------------------------------------------------
void change_time(int ms)
{
Form1->Timer2->Interval=ms;
Form1->Timer1->Interval=ms;
}
//----------------------------------------------
void __fastcall TForm1::Button6Click(TObject *Sender)
{
int msValue;
msValue = Form1->msl->Value;
change_time(msValue);
//Timer2->Interval=ms;
//Timer1->Interval=ms;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button10Click(TObject *Sender)
{
change_time(1);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button7Click(TObject *Sender)
{
change_time(10);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button8Click(TObject *Sender)
{
change_time(100);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button9Click(TObject *Sender)
{
change_time(1000);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button11Click(TObject *Sender)
{
change_time(10000);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button12Click(TObject *Sender)
{
powtorzenia=pole1->Value-1;
}
//---------------------------------------------------------------------------
unit1.h
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Buttons.hpp>
#include "CSPIN.h"
#include <ComCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
TButton *Button2;
TTimer *Timer1;
TPanel *Panel1;
TStaticText *StaticText1;
TLabel *Label1;
TTimer *Timer2;
TListBox *ListBox1;
TButton *Button3;
TButton *Button4;
TButton *Button5;
TButton *Button6;
TCSpinEdit *msl;
TStaticText *StaticText2;
TButton *Button7;
TButton *Button8;
TButton *Button9;
TButton *Button10;
TButton *Button11;
TProgressBar *ProgressBar1;
TCSpinEdit *pole1;
TStaticText *StaticText3;
TButton *Button12;
TLabel *Label2;
TButton *Button13;
TButton *Button14;
TButton *Button15;
TButton *Button16;
TButton *Button17;
TButton *Button18;
void __fastcall Button1Click(TObject *Sender);
void __fastcall Timer1Timer(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
void __fastcall Timer2Timer(TObject *Sender);
void __fastcall Button3Click(TObject *Sender);
void __fastcall Button4Click(TObject *Sender);
void __fastcall Button5Click(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall Button6Click(TObject *Sender);
void __fastcall Button10Click(TObject *Sender);
void __fastcall Button7Click(TObject *Sender);
void __fastcall Button8Click(TObject *Sender);
void __fastcall Button9Click(TObject *Sender);
void __fastcall Button11Click(TObject *Sender);
void __fastcall Button12Click(TObject *Sender);
private:
void __fastcall HotKey(TMessage &Msg);
public:
__fastcall TForm1(TComponent* Owner);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_HOTKEY,TMessage,HotKey)
END_MESSAGE_MAP(TForm)
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif