Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Interact with AutoHotkey from LA
Hi all, Happy Thanksgiving to everyone. I still use AutoHotkey quite a bit. My experience is mostly with v1, and v2 is rapidly taking over.
amazing-andrew wrote an interop for the AutoHotkey dll (version 1) which you can find here, AutoHotkey.Interop.
LucidMethod wrote a cool library called SharpAHK, which also uses AutoHotkey.Interop. As it was missing a function critical to displaying GUIs, I added one and created a Nuget package, sharpAHK_505.
That's what I used in the script below.

You can pass variables back and forth between LA and AutoHotkey, as you'll see.
I realize there may be little interest among LA users for AutoHotkey, since LA can do so much, but you may find some limited application for it.

I haven't done much testing with this - there may be memory leaks or other bugs.

Copy      Help
// script "SharpAHKtest6.cs"
/*/ nuget -\sharpahk_505; /*/ //.
using AutoHotkey.Interop;

string myContent = "Not updated!"; // Initialized for debugging

// Create AutoHotkey script to be loaded by
// AutoHotkey engine instance.
// (I suggest you avoid AHK comments in the script

string scriptString = @"#NoEnv
#SingleInstance force

Gui, Add, Edit, r9 vMyEdit w135, Text to appear inside control.
Gui, Add, Button, w80 gOutputz, Submit
gui, show


    Gui, Submit ; Submit the data from the GUI to update variables
    MsgBox, ,Testing AHK,% MyEdit

// Create the AutoHotkey engine
var ahk = AutoHotkeyEngine.Instance;

// Load the script

// Critical - if this 'while' loop is omitted,
// the script will exit immediately after the
// GUI very briefly appears.
// sharpAHK_505 has the isReady function,
// but AFAIK the original sharpAHK does not.

while (ahk.IsReady() == true) {
    // Use LA's 'Intellisense' to explore other
    // engine functions.
    // For example, 'getter' GetVar also has a 'setter',
    // SetVar

    myContent = ahk.GetVar("MyEdit");

// Do something with the variable retrieved"Contents is: " + myContent);

ahk = null;

Forum Jump:

Users browsing this thread: 1 Guest(s)