-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoIntoChannel.cpp
172 lines (139 loc) · 4.45 KB
/
AutoIntoChannel.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
// AutoIntoChannel.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
#include <stdio.h>
#include <iostream>
#include <windows.h>
#include <string>
#include <fstream>
#include <cstdlib>
int openFile(std::string address);
int simulateCtrlS();
void printDashEverySecond(int ms100);
HWND FindTeamSpeakWindow();
//DWORD errid;
int forceSucccess = 0;
short tryForcetime = 0;
std::string address = "start C:\\Users\\Public\\Desktop\\\"TeamSpeak 3 Client.lnk\"";
std::string address2 = "start C:\\Users\\Public\\Desktop\\\"TeamSpeak3Client.lnk\"";
int main()
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);//设置浅黄色
printf("开始打开文件\n");
if (openFile(address)!= 0) {
//errid = GetLastError();
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);//设置浅绿色
printf("开始打开文件成功11\n\n");
}
else if (openFile(address) != 0) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);//设置浅绿色
printf("开始打开文件成功12\n\n");
}
else if (openFile(address2) != 0) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);//设置浅绿色
printf("开始打开文件成功21\n\n");
}
else if(openFile(address2) != 0){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);//设置浅绿色
printf("开始打开文件成功22\n\n");
}
else {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);//设置浅红色
printf("开始打开文件失败try out,请查看日志\n\n");
Sleep(1000);
exit(114);
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);//设置浅黄色
printDashEverySecond(8);
FindTeamSpeakWindow();
do {
printDashEverySecond(5);
FindTeamSpeakWindow();
} while (forceSucccess != 1 && tryForcetime < 3);
if (forceSucccess != 1 && tryForcetime >= 3) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);//设置浅红色
printf("赋予窗口焦点失败01,请查看日志\n\n");
}
/*if (forceSucccess == 0) {
printDashEverySecond(5);
FindTeamSpeakWindow();
}
if (forceSucccess == 1) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);//设置浅绿色
printf("赋予窗口焦点成功\n\n");
}
else if (forceSucccess == 0) {
printDashEverySecond(5);
FindTeamSpeakWindow();
}
else {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);//设置浅红色
printf("赋予窗口焦点失败01,请查看日志\n\n");
}*/
printDashEverySecond(2);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);//设置浅黄色
printf("开始连接服务器\n");
simulateCtrlS();
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);//设置浅绿色
printf("连接服务器成功\n");
exit(114514);
}
void printDashEverySecond(int ms100) {
for(int i=0;i<ms100;i++) {
std::cout << "-";
Sleep(500); // Sleep for 1 second
}
std::cout << "\n";
}
int simulateCtrlS() {
// Press Ctrl key
keybd_event(VK_CONTROL, 0, 0, 0);
// Press S key
keybd_event('S', 0, 0, 0);
// Release S key
keybd_event('S', 0, KEYEVENTF_KEYUP, 0);
// Release Ctrl key
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
printDashEverySecond(5);
// Simulate pressing the 'Enter' key
keybd_event(VK_RETURN, 0, 0, 0);
// Release the 'Enter' key
keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
return 1;
}
int openFile(std::string address) {
if (system(address.c_str()) != -1) {
return 1;
}
else {
return 0;
}
}
HWND FindTeamSpeakWindow(){
HWND hwnd = NULL;
wchar_t className[512];
wchar_t windowName[512];
// Get the first top-level window
hwnd = GetTopWindow(NULL);
// Iterate through all top-level windows
while (hwnd != NULL)
{
// Get the class name of the window
GetClassNameW(hwnd, className, sizeof(className)/2);
// Get the window name of the window
GetWindowTextW(hwnd, windowName, sizeof(windowName)/2);
//printf("%ws\n", windowName);
// Check if the window name contains "TeamSpeak"
if (wcsstr(windowName, L"TeamSpeak") != NULL)
{
// Set the focus to the window
//SetFocus(hwnd);
//SetForegroundWindow(hwnd);
SwitchToThisWindow(hwnd, true);
printf("检测到赋予窗口焦点成功%ws\n\n", windowName);
forceSucccess = 1;
//break;
}
// Get the next top-level window
hwnd = GetNextWindow(hwnd, GW_HWNDNEXT);
}
return hwnd;
}