Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to compile trigger to exe?
#1
Hi,
I want to compile a trigger file to exe file. But it doesn't work. Is there anything wrong? Thank you so much!
Code:
Copy      Help
[code]// class "Hotkey triggers.cs"
/*/ role exeProgram; outputPath %folders.Workspace%\exe\Hotkey triggers; /*/
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.

        
        
        
        if (true) { //examples. To enable and test it, replace (!true) with (true) and run this script.
            hk["Ctrl+Alt+K"] = o => print.it("trigger action example 1", o.Trigger); //it means: when I press Ctrl+Alt+K, execute trigger action print.it(...)
            hk["Ctrl+Shift+F11"] = o => { //multiple statements
                var w1 = wnd.active;
                if (w1.Name.Like("* - Notepad")) keys.sendt("trigger action example 2\r\n");
                else print.it("trigger action example 2");
            };

            hk["Ctrl+Shift+1"] = o => TriggerActionExample(); //call other function. To find it quickly, click the function name here and press F12.
            hk["Ctrl+Shift+2"] = o => TriggerActionExample2(o.Window); //the function can be in any class or partial file of this project
            hk["Ctrl+Shift+3"] = o => script.run("Script example1.cs"); //run script in separate process
            hk["Ctrl+Shift+4", TKFlags.LeftMod | TKFlags.KeyModUp] = o => print.it("trigger with flags");
            
            //triggers that work only with some windows (when the window is active)
            
            Triggers.Of.Window("* WordPad", "WordPadClass");
            
            hk["Ctrl+F5"] = o => print.it("trigger action example 5", o.Trigger, o.Window);
            //hk[""] = o => {  };
            // ...

            
            Triggers.Of.Window(of: "notepad.exe"); //all windows of notepad.exe process
            
            hk["Ctrl+F5"] = o => print.it("trigger action example 6", o.Trigger, o.Window);
            //hk[""] = o => {  };
            
            hk["Ctrl+Shift+Enter"] = o =>keys.send("Home Enter");
            // ...
            Triggers.Of.Window("* - Jupyter Notebook - *", "Chrome_WidgetWin_*");
            hk[" Ctrl+,"] = o => keys.more.sendKey(KKey.Down); //just disable. Does not disable Ctrl+CapsLock etc.
            hk[" Ctrl+j"] = o => keys.more.sendKey(KKey.Left); //just disable. Does not disable Ctrl+CapsLock etc.
            hk[" Ctrl+l"] = o => keys.more.sendKey(KKey.Right); //just disable. Does not disable Ctrl+CapsLock etc.
            hk[" Ctrl+i"] = o => keys.more.sendKey(KKey.Up); //just disable. Does not disable Ctrl+CapsLock etc.
            
            // ...

            
            Triggers.Of.AllWindows();
            
            //disable or remap keys
            
            //hk["CapsLock"] = o => {  }; //just disable. Does not disable Ctrl+CapsLock etc.
            //hk["?+Ins"] = o => keys.more.sendKey(KKey.Apps); //remap key. Also Ctrl+Ins etc. To remap keys, use keys.more.sendKey or keys.sendL, not keys.send.
            //disable/enable triggers

            hk["Ctrl+Alt+Win+D"] = o => ActionTriggers.DisabledEverywhere ^= true;
            hk.Last.EnabledAlways = true;
        }
    }

    
    
    void TriggerActionExample() {
        print.it("trigger action example 3");
    }
    
}

[/code]
#2
Hi birdywen, you may need threading to make it work. Please see the code provided by Gintaras when I asked for help here, date is August 20, 2023.
I just compiled to an executable and the triggers work.

Best regards,
burque505
#3
Triggers in exe can be used like this example: https://www.libreautomate.com/api/Au.Tri...ggers.html

Or, if you want to compile all your triggers and toolbars, compile script "Triggers and toolbars". You can temporarily set its role exeProgram, compile, then restore default role.

I didn't test compiling a single file from folder "@Triggers and toolbars", but it is possible. Create new script project, copy script "Triggers and toolbars" (as the first file in the project folder) and class file "Hotkey triggers.cs" to it, set role exeProgram, compile. Not tested. Can copy only code from script "Triggers and toolbars" to your exe code. Maybe let the code run in separate thread. Maybe use /*/ c Hotkey triggers.cs /*/ instead of copying file "Hotkey triggers.cs".
#4
It worked! Thank you so much!


Forum Jump:


Users browsing this thread: 1 Guest(s)