- "Hi, I'm trying to learn about C#, and I have no basic knowledge about coding. I am using ChatGPT as a helper, and sorry for my broken English.
The code is like this.
// Clears the console for a fresh display of results
print.clear();
// Grouping mouse click coordinates
// Mouse coordinates in (x, y) format
var points = new[] {
(47, 845), // Point 1
(136, 845), // Point 2
(221, 845), // Point 3
(48, 784), // Point 4
(137, 784) // Point 5
};
// Function to open Notepad if it is not active
void OpenNotepad() {
var w = wnd.find(1, "*- Notepad", "Notepad");
if (w == null) {
// If Notepad is not found, open it and wait for it to be ready
run.it(@"C:\test folder\ThisLA.txt"); // Open file in the test folder
w = wait.until(2, () => wnd.find(1, "*- Notepad", "Notepad")); // Wait until Notepad opens
if (w == null) {
print.it("Error: Notepad window not found."); // Display error message if Notepad still not found
return; // Exit function if Notepad could not be found
}
}
w.Activate(); // Activate if already open
}
// Macro HeloA
void HeloA() {
OpenNotepad();
var w = wnd.find(1, "*- Notepad", "Notepad");
if (w == null) {
print.it("Failed to run HeloA: Notepad is not open.");
return;
}
// Click on points 1, 3, and 5
for (int i = 0; i < points.Length; i += 2) {
mouse.move(points[i].Item1, points[i].Item2); // Move mouse to specified point
mouse.click(); // Left-click the mouse
500.ms(); // Wait 500 ms
}
// Type text into Notepad
keys.sendt("Hello, this is script HeloA. Have a nice day!");
}
// Macro HeloB
void HeloB() {
OpenNotepad();
var w = wnd.find(1, "*- Notepad", "Notepad");
if (w == null) {
print.it("Failed to run HeloB: Notepad is not open.");
return;
}
// Click on points 2, 4, and 6
for (int i = 1; i < points.Length; i += 2) {
mouse.move(points[i].Item1, points[i].Item2);
mouse.click();
500.ms();
}
// Type text into Notepad
keys.sendt("Hello, this is script HeloB. Have a great day!");
}
// Run the main script
HeloA(); // Call Macro HeloA
HeloB(); // Call Macro HeloB
--- and itsaid eror cant open notepad
And I want each script to have its own void so I can run or test each code. Should I make it like a script or a class?"
And thank you