AutoHotkey custom module created, still in testing

I hesitated about posting this code yet as it’s still too rough, especially getting Intellisense to work right (I don’t have Resources.resx structured properly). Here goes anyway, though. :grinning:

UPDATE: Please see the new github repo if you’d like to build it yourself easily. ExecRaw code in action (code on github):

Loaded sharpAHK.dll into solution using Nuget(must be sharpAHK_505).

Script 1 just starts IE via COM through AHK’s “ComObjCreate” function.
Script 2 just does the same for Word.

Ahk1

ahk2

ie_com3.ahk:

#Persistent

StartIE()


return

StartIE()
{
	SetTimer, myLabel, -0
}

myLabel:
wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := True
wb.Navigate("Google.com")
SetTimer
ExitApp

wordcom.ahk:

#Persistent

StartWord()


return

StartWord()
{
	SetTimer, myLabel, -0
}

myLabel:
wb := ComObjCreate("Word.Application")
wb.Visible := True
SetTimer
ExitApp

LoadFile.cs:

using System;
using Robin.Core;
using Robin.Core.Attributes;
using System.ComponentModel;
using System.Windows.Forms;
using sharpAHK;

namespace Modules.AhkTest
{
    [Action(Order = 1, Category = "LoadScriptAndCallFunction")]
    [Throws("ActionError")] // TODO: change error name (or delete if not needed)
    public class LoadFile : ActionBase
    {
        [InputArgument, DefaultValue("ie_com3.ahk")]
        public string ScriptName { get; set; }
        [InputArgument, DefaultValue("StartIE")]
        public string FunctionName { get; set; }
        [OutputArgument, DefaultValue("Script completed successfully.")]
        public string AhkResult { get; set; }

        public override void Execute(ActionContext context)
        {
            try
            {
                var ahk = new AutoHotkey.Interop.AutoHotkeyEngine();
                ahk.LoadFile(ScriptName);
                ahk.ExecFunction(FunctionName);
                while (ahk.IsReady() == true)
                {
                    System.Threading.Thread.Sleep(100);
                }
                ahk.Reset();
                MessageBox.Show("Engine finished.");
                AhkResult = ("Finished successfully.");
            }
            catch (Exception e)
            {
                if (e is ActionException) throw;

                throw new ActionException("ActionError", e.Message, e.InnerException);
            }

            // TODO: set values to Output Arguments here
        }

    }
}

Solution Explorer:

SolutionExplorer

And the less-than-satisfactory Resources.resx:

Resources

UPDATE: New ‘ExecRaw’ action.

ExecRaw

I will continue to update this as I get more AutoHotkey functionality working properly.

Regards,
burque505

3 Likes