How to build a WriteLog External Shortcut Processor

Writelog version 11.20 introduces support for a user-written command processor called an External Shortcut Assembly.

What is this for?

An External Shortcut Assembly, once installed in WriteLog's Programs directory, adds new entries to WriteLog's "Command to Run" entry in the menu entry Setup/Keyboard Shortcuts.... Here is an example:

sc01.png

The "Add Shortcut" button maps the keyboard key (F1 in the example above) to the command provided in the assembly.

How would I write a command?

There are some very easy customizations you can provide with only a little effort. An especially easy example is to make one WriteLog keystroke do more than one operation, in sequence. The WriteLog Setup/Shortcut built-in capability will only run one command for one keystroke. If you have programming skills (or learn them) you can do a lot more than just string commands together as described in this example.

Steps to Create and Build using C#

On Microsoft's website, http://visualstudio.com, there is button labeled Free Visual Studio Trial. You can freely download and use their "Express" products to build a WriteLog Shortcut Assembly. The rest of these instructions assume you have installed Visual Studio Express Version 10 for C#. It is also possible use other .NET languages to build a WriteLog Shortcut Assembly, but only C# is described on this step-by-step page.

After installing Visual Studio Express version 10, create a new project.
Make up a name other than the name used in this example, MyWriteLogShortCuts.

 sc02.png

 

The wizard generated a file named Class1.cs. In the Solution Explorer window, change the name of your Class1.cs class to something else, like ShortcutProcessor sc03.png

It will ask whether to change all your references, and in this case, its useful to say Yes.
sc04.png

There are three assemblies (dll files) installed with WriteLog that you must add as References. All three are in WriteLog's Programs directory. Use right mouse button and "Add Reference..."
sc05.png

Browse to WriteLog's Programs folder and Add Reference for WriteLogExternalShortcuts.dll and...

sc06.png
Be sure you add References to all three of these dll files in WriteLog's Programs directory:
  1. WriteLogExternalShortcuts.dll
  2. WriteLogClrTypes.dll
  3. WriteLogShortcutHelper.dll
And be sure to set the Target Framework version to 3.5 in the Properties (WriteLog does not support the later frameworks):
sc09.png
Here is what the contents of your file ShortcutProcessor.cs might look like:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace MyWritelogShortcuts

{

    public class ShortcutProcessor : WriteLogShortcutHelper.ShortcutHelper

    {

        /* These are the names of the commands as they will appear

           in WriteLog's Keyboard Shortcuts "Command to run" list: */

        string[] CommandNames = new string[] {

                "My command 1",  // this is which == 0

                "My command 2"  // this is which == 1

                // ... and you can add as many as you like.

 

                // They will appear in WriteLog with "External:" prepended.

                // Look in the E's in that menu.

        };

 

        // you must have this property

        public override int ShortcutCount

        {            get { return CommandNames.Length; }         }

 

        // and you must have this one

        public override string this[int which]

        {

            get {

                if ((which < 0) || (which >= CommandNames.Length))

                    throw new IndexOutOfRangeException();

                return CommandNames[which];

            }

        }

 

        // and you must have this method

        public override void InvokeShortcut(int which, WriteLogClrTypes.IWriteL wl)

        {

            if ((which < 0) || (which >= CommandNames.Length))

                throw new IndexOutOfRangeException();

 

            // you can call methods on the wl object here. You are not limited

            // to the InvokeKeyboardCommand, but it makes a simple demonstration

            // because the result is to simply do exactly what WriteLog would

            // do if you set the CommandToRun to ToolsGraphs or ViewOnlyTheLog.

            switch (which)

            {

                case 0: // "My command 1" does two existing keyboard commands in sequence

                    wl.InvokeKeyboardCommand("RadioHeadphonesSplit");

                    wl.InvokeKeyboardCommand("MessageShift09");

                    break;

 

                case 1: // My command 2"

                    wl.InvokeKeyboardCommand("ViewOnlyTheLog");

                    break;

            }

        }

     }

}

 

If you use the InvokeKeyboardCommand method, the list of command strings available is that in WriteLog's Keyboard shortcut editor:
sc10.png

The sample above simply uses the InvokeKeyboardCommand method to invoke one (or two) of the commands that WriteLog's own Keyboard shortcut editor can also invoke. If you learn C# programming, you can figure out how to make the your shortcut do much more. It can, for example, query the frequency and mode the radio is tuned to, it can read and write the fields in the Entry Windows, and it can command the radios to change frequency or modes and more.

An Example

Here you can download a sample that was created using the above instructions. Download sample

The sample also includes the project KeyboardShortcutTester.sln. Open it first and Visual Studio will open not only the sample, but also a project with a debugging tool that works with Visual Studio Express.

Install in WriteLog's Programs and writelog.ini

To make WriteLog see your shortcuts, you must do three things:

  1. Right mouse on your project name and Build it.
  2. Then copy the resulting .dll file in your bin\Release directory into WriteLog's Programs folder. Note that Visual Studio will have copied WriteLog's own assemblies into its build folder, but don't copy them back into the WriteLog Programs folder. You must have adminstrator privileges to copy into the Programs directory. If you are not an admin user on your system, you will have to do something like switch user, or else use the Windows Explorer to copy in the file and it will ask you for permission to copy into the protected Programs directory.
  3. And you must also change two settings in writelog.ini:
    [Configuration]
    ExtShortcutAssembly=MyWritelogShortcuts
    Use the name of your DLL, but without the .dll
    ExtShortcutClass=MyWritelogShortcuts.ShortcutProcessor
The ExtShortcutClass entry is the full name of your .NET class using "dot notation". That means the name of your dll (without the .dll", followed by the dot character, followed by the name you chose for your class.