Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Asking very basic command
#1
  • "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.
I am trying to make a basic script to run continuously with start, pause, and stop, and to move to points 1, 2, 3, 4, and 5, but somehow I am already stuck and can't open Notepad.
The code is like this.

 
Code:
Copy      Help
// 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?"


Code:
Copy      Help
https://prnt.sc/tHZwIxifhCuC


And thank you


Messages In This Thread
Asking very basic command - by Rudeyz - 11-01-2024, 10:26 PM
RE: Asking very basic command - by Rudeyz - 11-04-2024, 05:59 AM
RE: Asking very basic command - by Gintaras - 11-04-2024, 08:06 AM
RE: Asking very basic command - by Rudeyz - 11-11-2024, 06:47 AM
RE: Asking very basic command - by Gintaras - 11-11-2024, 07:29 AM
RE: Asking very basic command - by Rudeyz - 11-15-2024, 09:31 AM
RE: Asking very basic command - by Rudeyz - 12-11-2024, 09:28 AM
RE: Asking very basic command - by Gintaras - 12-11-2024, 10:07 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)