-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathMainView.cpp
469 lines (433 loc) · 10.1 KB
/
MainView.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
// MainView.cpp : implementation of the CMainView class
//
#include "stdafx.h"
#include "按键助手.h"
#include "ChildDlg.h"
#include "MiniDlg1.h"
#include "MainDoc.h"
#include "MainView.h"
#include "MainFrm.h"
#include "VMKey.h"
#include <afxwin.h>
#include <math.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
volatile int nCommand;
void CarryKry(bool way,short vKey);
CString vKeyToChar(short vKey);
long nListNum;
short snNewKeyStu=0,snOldKey[120];
long lDerfer=0;
//CMiniDlg *m_dlgMini;
/////////////////////////////////////////////////////////////////////////////
// CMainView
IMPLEMENT_DYNCREATE(CMainView, CView)
BEGIN_MESSAGE_MAP(CMainView, CView)
//{{AFX_MSG_MAP(CMainView)
ON_WM_CREATE()
ON_COMMAND(ID_CTRL_PAUSE, OnCtrlPause)
ON_COMMAND(ID_CTRL_REC, OnCtrlRec)
ON_COMMAND(ID_CTRL_RUN, OnCtrlRun)
ON_COMMAND(ID_CTRL_STOP, OnCtrlStop)
ON_WM_TIMER()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
///////////////////////////////////////////////////////
/*long StrToLong(char const *string)
{
return atol(string);
}*/
/////////////////////////////////////////////////////////////////////////////
// CMainView construction/destruction
CMainView::CMainView()
{
// TODO: add construction code here
}
CMainView::~CMainView()
{
}
BOOL CMainView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMainView drawing
void CMainView::OnDraw(CDC* pDC)
{
CMainDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMainView printing
BOOL CMainView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMainView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMainView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMainView diagnostics
#ifdef _DEBUG
void CMainView::AssertValid() const
{
CView::AssertValid();
}
void CMainView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMainDoc* CMainView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMainDoc)));
return (CMainDoc*)m_pDocument;
}
#endif //_DEBUG
//-----------------------------------------------------------------------------
// CMainView message handlers
CChildDlg *m_dlgChild;
UINT ActionRunAfx(LPVOID pParam);
int CMainView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
m_dlgChild=new CChildDlg();
m_dlgChild->Create(IDD_CHILD,this);
m_dlgChild->MoveWindow(0,0,1280,1024);
m_dlgChild->ShowWindow(SW_SHOW);
HWND hWnd = GetSafeHwnd();
AfxBeginThread(ActionRunAfx,this, THREAD_PRIORITY_NORMAL);
//////////////////////////////////////////////
for(int j=0;j<120;j++) {snOldKey[j]=0;}
///////////////////////////////////////////////
SetTimer(2,33,NULL);
return 0;
}
//---------------------------------------------------------------
void CMainView::OnCtrlPause()
{
nCommand=COMPAUSE;
KillTimer(1);
}
//————————————————————————————————————————————
void CMainView::OnCtrlRec()
{
CWnd* pMain=AfxGetMainWnd();
pMain->ShowWindow(SW_MINIMIZE);
m_dlgChild->m_ActionList.DeleteAllItems();
m_dlgChild->EnableWindow(false);
nListNum=0;
SetTimer(1,10,NULL);
if (m_dlgChild->m_bAlwayRec==1) SetTimer(3,40,NULL);
for(int j=0;j<120;j++) {snOldKey[j]=0;}
snNewKeyStu=0;
}
//CMiniDlg *m_dlgMini;
//————————————————————————————————————————————
void CMainView::OnCtrlStop()
{
nCommand=COMSTOP;
KillTimer(1);
KillTimer(3);
CWnd* pMain=AfxGetMainWnd();
pMain->ShowWindow(SW_SHOW);
m_dlgChild->EnableWindow(true);
}
//---------------------------------------------------------------------------
//////////////////录制点击动作//////////////////////
int nOldCom;
void CMainView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent==1)
{
lDerfer+=10;
for (int i=0;i<120;i++)
{
snNewKeyStu=GetAsyncKeyState(i);
if(snNewKeyStu==0)
{
if(snOldKey[i]==-32768) CarryKry(false,i);
}
else if(snNewKeyStu==1)
{
CarryKry(true,i);
CarryKry(false,i);
}
else if(snNewKeyStu==-32767)
{
if(snOldKey[i]==0) CarryKry(true,i);
}
snOldKey[i]=snNewKeyStu;
}
}
if(nIDEvent==2)
{
if(GetAsyncKeyState(115)==-32767) this->OnCtrlRec();
if(GetAsyncKeyState(116)==-32767) this->OnCtrlRun();
if(GetAsyncKeyState(117)==-32767) this->OnCtrlPause();
if(GetAsyncKeyState(118)==-32767) this->OnCtrlStop();
if(nCommand==COMSTOP && nOldCom!=COMSTOP) this->OnCtrlStop();
nOldCom=nCommand;
}
if(nIDEvent==3)
{
lDerfer+=10;
CarryKry(0,0);
}
CView::OnTimer(nIDEvent);
}
//----------------------------------------------------------------------------
UINT ActionRunAfx(LPVOID pParam)
{
while(true)
{ Sleep(50);
while(nCommand==COMSTOP) {Sleep(50);}
if (nCommand==COMRUN)
{
CString Action,strValue;
for (int i=0;i<=m_dlgChild->m_ActionList.GetItemCount();i++)
{ if(nCommand==COMSTOP) break;
while(nCommand==COMPAUSE) {Sleep(50);}
Action=m_dlgChild->m_ActionList.GetItemText(i,1);
strValue=m_dlgChild->m_ActionList.GetItemText(i,2);
if (Action=="延时")
{
Sleep(StrToLong(strValue));
}
if (Action=="移动鼠标")
{ long PosX,PosY;
CString PX,PY;
PX=strValue.Left(strValue.FindOneOf(","));
PY=strValue.Right(strValue.GetLength()-strValue.FindOneOf(",")-1);
PosX=StrToLong(PX);
PosY=StrToLong(PY);
SetCursorPos(PosX,PosY);
}
if (Action=="按下")
{
int Key;
if (strValue=="MouseLeft") mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
else if(strValue=="MouseMid") mouse_event(MOUSEEVENTF_MIDDLEDOWN,0,0,0,0);
else if(strValue=="MouseRight") mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
else if(Key=KeyList(strValue)) keybd_event(Key,MapVirtualKey(Key,0),0,0);
}
if (Action=="抬起")
{ int Key;
if (strValue=="MouseLeft") mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
else if(strValue=="MouseMid") mouse_event(MOUSEEVENTF_MIDDLEUP,0,0,0,0);
else if(strValue=="MouseRight") mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
else if(Key=KeyList(strValue)) keybd_event(Key,MapVirtualKey(Key,0),KEYEVENTF_KEYUP,0);
}
}
nCommand=COMSTOP;
}
}
return 0;
}
void CMainView::OnCtrlRun()
{ CWnd* pMain=AfxGetMainWnd();
//CWnd *pMain=AfxGetMainWnd();
//::ShowWindow(*pMain,SW_HIDE);
//this->ShowWindow(SW_HIDE);
//m_dlgMini=new CMiniDlg;
//m_dlgMini->Create(IDD_DIALOGBAR,this);
//m_dlgMini->ShowWindow(SW_SHOW);
//CWnd* pMain=AfxGetMainWnd();
pMain->ShowWindow(SW_MINIMIZE);
//this->ShowWindow(SW_MINIMIZE);
nCommand=COMRUN;
}
//////////////way 按下为true 抬起为false///////////
POINT OldPos,NewPos;
void CarryKry(bool way,short vKey)
{
CString str1,str2;
str1.Format("%d",nListNum);
m_dlgChild->m_ActionList.InsertItem(nListNum,str1);
m_dlgChild->m_ActionList.SetItemText(nListNum,1,"延时");
str1.Format("%d",lDerfer);
m_dlgChild->m_ActionList.SetItemText(nListNum,2,str1);
nListNum++;
lDerfer=0;
GetCursorPos(&NewPos);
str1.Format("%d",nListNum);
m_dlgChild->m_ActionList.InsertItem(nListNum,str1);
m_dlgChild->m_ActionList.SetItemText(nListNum,1,"移动鼠标");
str1.Format("%d",NewPos.x);
str1+=',';
str2.Format("%d",NewPos.y);
str2=str1+str2;
m_dlgChild->m_ActionList.SetItemText(nListNum,2,str2);
nListNum++;
if(vKey!=0)
{
if (way==true)
{
str1.Format("%d",nListNum);
m_dlgChild->m_ActionList.InsertItem(nListNum,str1);
m_dlgChild->m_ActionList.SetItemText(nListNum,1,"按下");
m_dlgChild->m_ActionList.SetItemText(nListNum,2,vKeyToChar(vKey));
nListNum++;
}
else
{
str1.Format("%d",nListNum);
m_dlgChild->m_ActionList.InsertItem(nListNum,str1);
m_dlgChild->m_ActionList.SetItemText(nListNum,1,"抬起");
m_dlgChild->m_ActionList.SetItemText(nListNum,2,vKeyToChar(vKey));
nListNum++;
}
}
}
CString vKeyToChar(short vKey)
{ CString ch;
if ((vKey>=48 && vKey<=57) || (vKey>=65 && vKey<=90))
return char(vKey);
else
{
switch (vKey)
{
case 13:
ch = "ENTER";
break;
case 9:
ch = "TAB";
break;
case 38:
ch = "UPARROW";
break;
case 40:
ch = "DOWNARROW";
break;
case 37:
ch = "LEFTARROW";
break;
case 39:
ch = "RIGHTARROW";
break;
case 112:
ch = "F1";
break;
case 113:
ch = "F2";
break;
case 114:
ch = "F3";
break;
case 115:
ch = "F4";
break;
case 116:
ch = "F5";
break;
case 117:
ch = "F6";
break;
case 118:
ch = "F7";
break;
case 119:
ch = "F8";
break;
case 120:
ch = "F9";
break;
case 121:
ch = "F10";
break;
case 122:
ch = "F11";
break;
case 123:
ch = "F12";
break;
case 32:
ch = "SPACEBAR";
break;
case 17:
ch = "Ctrl";
break;
case 8:
ch = "SPACEBAR";
break;
case 18:
ch = "ALT";
break;
case 91:
ch = "LeftWindows";
break;
case 92:
ch = "RightWindows";
break;
case 93:
ch = "menu";
break;
case 16:
ch = "SHIFT";
break;
case 1:
ch = "MouseLeft";
break;
case 97:
ch = "NUM1";
break;
case 98:
ch = "NUM2";
break;
case 99:
ch = "NUM3";
break;
case 100:
ch = "NUM4";
break;
case 101:
ch = "NUM5";
break;
case 102:
ch = "NUM6";
break;
case 103:
ch = "NUM7";
break;
case 104:
ch = "NUM8";
break;
case 105:
ch = "NUM9";
break;
case 46:
ch = "Delete";
break;
case 2:
ch = "MouseRight";
break;
case 96:
ch = "NUM0";
break;
case 110:
ch = ".";
break;
case 27:
ch = "ESC";
break;
}
return ch;
}
}