
errors:
Compilation: 2 errors
Script1.cs(10,6): error CS0117: 'keys' does not contain a definition for 'onKeyDown'
Script1.cs(25,9): error CS0165: Use of unassigned local variable 'cts'
script:
// Toggle spam of "T" key at 100 presses per second in LibreAutomate
// Press T once to start, press T again to stop.
using System;
using System.Threading;
bool spamming = false;
CancellationTokenSource cts;
keys.onKeyDown(KKey.T, k => {
if (!spamming) {
// Start spamming
spamming = true;
cts = new CancellationTokenSource();
Task.Run(() => {
while (!cts.Token.IsCancellationRequested) {
keys.send("T");
Thread.Sleep(10); // 10 ms delay = ~100 presses/sec
}
});
print.it("T spam started.");
} else {
// Stop spamming
spamming = false;
cts.Cancel();
print.it("T spam stopped.");
}
});