Posts: 4
Threads: 1
Joined: Oct 2025
10-17-2025, 05:30 AM
(This post was last modified: 10-17-2025, 03:19 PM by AshesOfHegemony.)
Im trying to learn LibreAutomate. I created small macro to spam spacebar every 20 milliseconds. I set it to toggle on hotkey press (Shift + Numpad+). It works and runs as intended, but if i run it for longer than a few seconds it takes multiple attempts to toggle it off. I'm not sure what im doing wrong here or if this is a limitation of the LibreAutomate itself?
/*/ ifRunning end; /*/
script.setup(trayIcon: true, sleepExit: true, exitKey: KKey.MediaStop, pauseKey: KKey.MediaPlayPause);
sound.speak("Toggle On");
bool toggle = false;
while (!toggle)
{
keys.send("Space");
}
The hotkey is assigned in the "hotkey triggers" file
using Au.Triggers;
partial class Program {
[Triggers]
void HotkeyTriggers() {
var hk = Triggers.Hotkey;
//Add hotkey triggers here.
//To add triggers can be used triggerSnippet or menu TT > New trigger.
//To add trigger scopes (window, program) can be used Ctrl+Shift+Q.
//Click the Run button to apply changes after editing.
//More info in Cookbook.
hk["Ctrl+Shift+T"] = o => Triggers.ShowTriggersListWindow();
hk["Shift+Add"] = o => script.run(@"Game Spacebar.cs");
..........
Any help would be appreciated.
Posts: 12,239
Threads: 144
Joined: Dec 2002
10-17-2025, 05:46 AM
(This post was last modified: 10-17-2025, 05:50 AM by Gintaras.)
Is it full script? What is the purpose of the `toggle` variable?
But I see a possible problem with this code. It sends Space key too frequently. Likely the active app is too slow to process it. Then OS buffers many key events and sends them to the app even (possibly long) after the script ended. There is no way to know whether the target app processed sent keys. Try to make slower. For example keys.send("Space"); 100.ms(); .
Posts: 4
Threads: 1
Joined: Oct 2025
10-17-2025, 02:56 PM
(This post was last modified: 10-17-2025, 03:39 PM by AshesOfHegemony.)
I use a corsair keyboard with the ICUE software. I have an issue where the hardware drivers for the corsair bus keep corrupting for some reason(possibly because of the speed of input) causing my macro to no longer work and the toggle key to be non-functional. I got annoyed at reinstalling the software multiple times a day so i decided to find some macro software that could get the job done. I was able to create a functional macro in autohotkey, but then i realized AHK was blocked by the game i am playing. I'm not using a script to hack the game or cheat or anything like that. I just need a simple high speed loop so i can get into a pilot seat of an aircraft before other players do by spamming spacebar(the other players are also spamming spacebar or using a macro to do it so getting the pilot seat is still a 50% chance roughly). The server tick rate for the game i am playing is 60 hz, so it registers input every 16.6666 milliseconds. This is why my input needs to be every 20 milliseconds.
The purpose of toggle was to create my own variable to try a while(!toggle) loop, it is not being used at this point. That was before i realized how script.pause worked and shortly after realized i didnt even need script.pause because the HK command in the triggers file. Im just not sure if the script closing with the hot key press is not working properly because of some buffer overflow, or because its closing the application everytime, or if its actually a limitation of the scripting language itself. I mean its C# so i assumed execution would be very speedy. The script is working for the game i play, but it wont turn off properly sometimes. I also wanted to add some functionality to play a sound when it turns on and when it turns off. If the script could continue running in the tray and wait/listen for a toggle key combo without closing, that is probably the ideal way to get it to function properly. Sorry im not the best programmer, but i did go to school for computer science. I would use AI as an assist, but we both know its going to give me garbage code for LA.
Quote:Is it full script? What is the purpose of the `toggle` variable?
Edit: I just realized my code posted previously did not have a programmed delay. Even with delay it is still locking up and not closing properly, requiring multiple hotkey toggles to shut it off.
This is the full script. Here is what im using now:
/*/ ifRunning end; /*/
script.setup(trayIcon: true, sleepExit: true, exitKey: KKey.MediaStop, pauseKey: KKey.MediaPlayPause);
sound.speak("Toggle On");
bool toggle = false;
while (!toggle)
{
keys.send("Space");
20.ms();
}
Posts: 12,239
Threads: 144
Joined: Dec 2002
This should work.
// script "BF6 spacebar.cs"
/*/ ifRunning end; /*/
script.setup(trayIcon: true, sleepExit: true, exitKey: KKey.MediaStop);
opt.key.KeySpeed = 15;
opt.key.NoBlockInput = true;
opt.key.NoModOff = true;
while (true)
{
keys.send("Space");
}
Without options NoBlockInput and NoModOff the keys.send makes triggers unreliable.
The speed depends not on the language. It depends on: 1. The target app. 2. OS and computer speed. 3. Delays added by the "send keys" function.
Also try this. The sendL function does not use the "send keys" reliability features that interfere with triggers.
// script "BF6 spacebar2.cs"
/*/ ifRunning end; /*/
script.setup(trayIcon: true, sleepExit: true, exitKey: KKey.MediaStop);
while (true)
{
keys.sendL("Space");
15.ms();
}
Posts: 4
Threads: 1
Joined: Oct 2025
10-17-2025, 04:09 PM
(This post was last modified: 10-17-2025, 04:12 PM by AshesOfHegemony.)
Thank you very much!
This one works flawlessly:
Quote:This should work.
Code:
// script "BF6 spacebar.cs"
/*/ ifRunning end; /*/
script.setup(trayIcon: true, sleepExit: true, exitKey: KKey.MediaStop);
opt.key.KeySpeed = 15;
opt.key.NoBlockInput = true;
opt.key.NoModOff = true;
while (true)
{
keys.send("Space");
}
My next and final question is; how do i get the sound.speak("Toggle Off"); to play after the macro is toggled off in this code?
/*/ ifRunning end; /*/
script.setup(trayIcon: true, sleepExit: true, exitKey: KKey.MediaStop);
opt.key.KeySpeed = 15;
opt.key.NoBlockInput = true;
opt.key.NoModOff = true;
while (true)
{
keys.send("Space");
}
sound.speak("Toggle Off");
Im getting a compilation error at sound.speak();
Compilation: 1 warnings >>
Warnings can be disabled with C# #pragma warning or in Properties.
BF6 Spacebar2.cs(12,1): warning CS0162: Unreachable code detected
The sound effect is not being read before the script closes.
Posts: 12,239
Threads: 144
Joined: Dec 2002
With ifRunning end , the script ends before it starts speaking "Toggle Off".
Try this.
// script "BF6 spacebar.cs"
/*/ ifRunning run; /*/
script.setup(trayIcon: !true, sleepExit: true, lockExit: true);
using var mutex = new Mutex(true, "mutex-BF6-spacebar", out bool createdNew);
run.thread(() => { sound.speak(createdNew ? "Toggle On" : "Toggle off"); }, background: false);
if (createdNew) {
WndUtil.CreateMessageOnlyWindow("#32770", script.name);
} else {
int id = wnd.findFast(script.name, "#32770", messageOnly: true).ProcessId;
if (id != 0) script.end(id);
return;
}
while (true) {
keys.sendL("Space");
15.ms();
}
Posts: 4
Threads: 1
Joined: Oct 2025
10-18-2025, 11:59 AM
(This post was last modified: 10-18-2025, 12:01 PM by AshesOfHegemony.)
Thanks so much. This is exactly what i needed! The toggle sound effect plays during execution. YES.
/*/ ifRunning run; /*/
script.setup(trayIcon: !true, sleepExit: true, lockExit: true);
using var mutex = new Mutex(true, "mutex-BF6-spacebar", out bool createdNew);
run.thread(() => { sound.speak(createdNew ? "Toggle On" : "Toggle off"); }, background: false);
if (createdNew) {
WndUtil.CreateMessageOnlyWindow("#32770", script.name);
} else {
int id = wnd.findFast(script.name, "#32770", messageOnly: true).ProcessId;
if (id != 0) script.end(id);
return;
}
opt.key.KeySpeed = 15;
opt.key.NoBlockInput = true;
opt.key.NoModOff = true;
while (true)
{
keys.send("Space");
}
Edit: This is ultimately the version i settled on because for some reason, keys.sendL() is skipping key presses in the game window, but works fine in every other window. Not sure what the issue is there.
|