1.6.8162

March - Keybinds and DI improvements

C# Scripting - Keybinds prototype

New instrument which allows to initialize hotkeys right from scripts.

csharp
[Keybind("p")] // Simple example - triggers when 'p' is pressed
[Keybind("Ctrl+2")] // Triggers only when 'Ctrl + 2' is pressed
[Keybind("Ctrl+2", IgnoreModifiers = true)] // Triggers on ANY combination containing 'Ctrl + 2' (e.g., 'Ctrl + Alt + 2')
public void OnKey(){
    Log.Info("Key pressed");
}

[Keybind(Hotkey = "4", SuppressKey = false)] // Handles the key, but it will still pass through to other apps
public void HandleKeyWithInjectedServices(IAuraEventLoggingService loggingService){
    Log.Info("Key pressed");
    loggingService.LogMessage(new AuraEvent(){ Text = "Message", Loglevel = FluentLogLevel.Info });
}

C# Scripting - Dependency Injection improvements

If you're using GetService somewhere in the code - you're already using DI system in EyeAuras. I've made some improvements in that part which should simplify the scripts

Here is how exactly same script looks like in 3 different forms:

Current approach - get APIs via GetService

csharp
var sendInput = GetService<ISendInputScriptingApi>();
sendInput.MouseMoveTo(200, 100); // Moves the mouse to X200 Y100
sendInput.MouseRightClick(); // Performs a right mouse click

Now two new approaches which you could(and should!) start using in your scripts. I am thinking about automatically injecting current APIs (such as SendInput) into your scripts - this would simplify and generalize the code. E.g. for ISendInputScriptingApi the name would be SendInput (like in example below), for IPlaySoundScriptingApi - PlaySound, for ComputerVision that could be something like IComputerVisionExperimentalScriptingApi Cv { get; init; } I will publish this as a separate update.

csharp
ISendInputScriptingApi SendInput { get; init; } // Automatically initialized when the script starts

SendInput.MouseMoveTo(200, 100); // Moves the mouse to X200 Y100
SendInput.MouseRightClick(); // Performs a right mouse click

Now

csharp
[Dependency] ISendInputScriptingApi SendInput { get; set; }

SendInput.MouseMoveTo(200, 100); // Moves the mouse to X200 Y100
SendInput.MouseRightClick(); // Performs a right mouse click

Bugfixes/Improvements

  • [Scripting] Improved performance of scripts first start a bit (3-5%)