Beispiel #1
0
    void AutotextTriggers()
    {
        var tt = Triggers.Autotext;
        var tr = Triggers.Autotext.SimpleReplace;

        //examples of autotext triggers

        tt["los"] = o => o.Replace("Los Angeles");
        tt["WIndows", TAFlags.MatchCase] = o => o.Replace("Windows");

        tt.DefaultPostfixType = TAPostfix.None; //set some options for triggers added afterwards
        tt["<b>"]             = o => o.Replace("<b>[[|]]</b>");

        Triggers.Options.BeforeAction = o => { AOpt.Key.TextOption = KTextOption.Paste; }; //set AOpt options for trigger actions added afterwards
        tt["#file"] = o => {
            o.Replace("");
            using var fd = new System.Windows.Forms.OpenFileDialog();
            if (fd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            AKeys.Text(fd.FileName);
        };

        Triggers.Options.BeforeAction = null; tt.DefaultPostfixType = default; //reset some options

        //examples of simple text replacements

        tr["#su"] = "Sunday"; //the same as tt["#su"] = o => o.Replace("Sunday");
        tr["#mo"] = "Monday";

        //these triggers will work only in Notepad window

        Triggers.Of.Window("* Notepad", "Notepad");
        tr["#tu"] = "Tuesday";
        tr["#we"] = "Wednesday";
        Triggers.Of.AllWindows(); //reset

        //with confirmation

        tt.DefaultFlags |= TAFlags.Confirm; //add flag
        tr["#th"]        = "Thursday";
        tr["#fr", postfixType : TAPostfix.None] = "Friday";
        tt.DefaultFlags &= ~TAFlags.Confirm; //remove flag

        //To add triggers can be used snippets. Start typing "trig" and you will see snippets in the completion list.
    }
Beispiel #2
0
    void HotkeyTriggers()
    {
        var hk = Triggers.Hotkey;

        //examples of hotkey triggers

        hk["Ctrl+Alt+K"]     = o => AOutput.Write(o.Trigger); //it means: when I press Ctrl+Alt+K, execute action "AOutput.Write(o.Trigger)"
        hk["Ctrl+Shift+F11"] = o => {                         //action can have multiple statements
            var w1 = AWnd.FindOrRun("* Notepad", run: () => AExec.Run(AFolders.System + "notepad.exe"));
            AKeys.Text("text");
            500.ms();
            w1.Close();
        };
        hk["Ctrl+Shift+1"] = o => TriggerActionExample();          //action code can be in other function. To find it quickly, Ctrl+click the function name here.
        hk["Ctrl+Shift+2"] = o => TriggerActionExample2(o.Window); //the function can be in any class or partial file of this project folder
        hk["Ctrl+Shift+3"] = o => ATask.Run("Script example1.cs"); //run script in separate process. Then don't need to restart triggers when editing the script.

        //triggers that work only with some windows (when the window is active)

        Triggers.Of.Window("* WordPad", "WordPadClass");

        hk["Ctrl+F5"] = o => AOutput.Write("action 1", o.Trigger, o.Window);
        //hk[""] = o => {  };
        //...

        Triggers.Of.Windows(",,notepad.exe"); //all windows of notepad.exe process

        hk["Ctrl+F5"] = o => AOutput.Write("action 2", o.Trigger, o.Window);
        //hk[""] = o => {  };
        //...

        //...

        //disable/enable triggers
        Triggers.Of.AllWindows();
        hk["Ctrl+Alt+Win+D"]  = o => ActionTriggers.DisabledEverywhere ^= true;
        hk.Last.EnabledAlways = true;

        //To add triggers can be used snippets. Start typing "trig" and you will see snippets in the completion list.
        //For more info click word ActionTriggers above and press F1.
    }
Beispiel #3
0
partial class Script : AScript { [STAThread] static void Main(string[] a) => new Script(a); Script(string[] args)   //;;;
//Click the ► button on the toolbar to run the script.

                                 {
                                     AOutput.Write("The programming language is C#.");
                                     if (ADialog.ShowYesNo("Run Notepad?", "The script will add some text and close Notepad after 2 s."))
                                     {
                                         AExec.Run(AFolders.System + @"Notepad.exe");
                                         var w = AWnd.Wait(5, active: true, "*- Notepad"); //to create this code can be used the Code menu
                                         50.ms();
                                         AKeys.Text("some text");
                                         2.s();
                                         AKeys.Key("Ctrl+Z"); //Undo
                                         w.Close();
                                     }

                                     string linkText = "Read about code editor features",
                                            linkUrl  = "https://www.quickmacros.com/au/help/editor/Code editor.html";

                                     AOutput.Write($"<><link \"{linkUrl}\">{linkText}</link>");
                                 }
Beispiel #4
0
partial class Script : AScript { [STAThread] static void Main(string[] a) => new Script(a); Script(string[] args) { //;;;

/*
The programming language is C#.

In scripts you can use classes/functions of the automation library provided by
this program, as well as of .NET Core and everything that can be used in C#.
Also you can create and use new functions, classes, libraries and .exe programs.

Script properties are saved in /*/ /*/ comments at the very start of script.
You can change them in the Properties dialog.

Like all C# programs, a script starts with standard code: using directives,
class and function Main where the program starts. Click the small [+] box at
the top-left to see and edit that code when need. The //. and //; are used to
fold (hide) code.

To avoid 'static' everywhere, function Main creates a class instance. Your script
code is in the constructor function. The function and the class end with } and }.

To run a script, you can click the ► Run button on the toolbar, or use command line,
or call ATask.Run from another scrit, or in Options set to run at startup.

Triggers such as hotkeys, autotext, mouse and window are used to execute functions
in a running script. Also you can create custom toolbars and menus. To start
using them: menu File -> New -> Examples -> @Triggers and toolbars.
*/

//Examples of automation functions.

AOutput.Write("Main script code.");

ADialog.Show("Message box.");

AExec.Run(AFolders.System + "notepad.exe");
var w = AWnd.Wait(0, true, "*- Notepad");
AKeys.Key("F5 Enter*2");
AKeys.Text(w.Name);
2.s();
w.Close();
var w2 = AWnd.Wait(-3, true, "Notepad", "#32770");
if(!w2.Is0) {
	500.ms();
	var c = +w2.Child(null, "Button", skip: 1); // "Don't Save"
	AMouse.Click(c);
	500.ms();
}

//Examples of .NET functions.

string s = "Example";
var b = new System.Text.StringBuilder();
for(int i = 0; i < s.Length; i++) {
	b.Append(s[i]).AppendLine();
}
MessageBox.Show(b.ToString());

//Example of your function and how functions can share variables.

_sharedVariable = 1;
FunctionExample("Example");
AOutput.Write(_sharedVariable);

} //end of main function