Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
simple toggle macro
#2
Currently AI have not enough knowledge about LibreAutomate to create working code. I tried to ask this question too, and got another non-working code.

But when I gave it relevant LibreAutomation documentation articles, AI created this code (just forgot to assign false/null to the variables, I fixed it). And it works. I used OpenAI model `gpt-5` via API.
 
Code:
Copy      Help
bool sending=false;
Thread? worker=null;

var at = new Au.Triggers.ActionTriggers();

at.Hotkey["T"] = o => {
    sending = !sending;
    print.it(sending ? "T spam ON" : "T spam OFF");
    if (sending && worker is null) {
        worker = run.thread(() => {
            while (sending) {
                keys.more.sendKey(KKey.T); // press and release T
                10.ms(); // ~100 per second (see note below)
            }
            worker = null;
        });
    }
};


at.Hotkey["Esc"] = o => script.end();

at.Run();

I would do it differently, but this works too.

You probably will want to move that code to your `Hotkey triggers` file. Then need to modify it slightly. Code to paste in file `Hotkey triggers`:
 
Code:
Copy      Help
        bool sending = false;
        Thread worker = null;
        hk["F9"] = o => {
            sending = !sending;
            print.it(sending ? "T spam ON" : "T spam OFF");
            if (sending && worker is null) {
                worker = run.thread(() => {
                    try {
                        while (sending) {
                            keys.more.sendKey(KKey.T); // press and release T
                            10.ms(); // ~100 per second (see note below)
                        }
                    }

                    catch (Exception) { sending = false; }
                    worker = null;
                });
            }
        };

Here I changed the hotkey to F9.

Most of this code could be moved to a separate script.


Messages In This Thread
simple toggle macro - by lumenant - 08-12-2025, 03:59 PM
RE: simple toggle macro - by Gintaras - 08-12-2025, 06:26 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)