AutoHotKey script activity: pass variable to rest of UiPath workflow



Hi, thanks in advance for all help.
I would like to run an AHK script using “Run Auto Hot Key script”, set variables, and pass them to UiPath.

In the past I’ve been able in Visual Studio to pass variables from both AutoHotkey.Interop.Dll and AutoHotKey.dll to Visual Basic. There the syntax seems to be different than what I’ll need here. Here’s a sample of a working .vb example in VB.NET, using a form with a button to execute this code:

Imports AutoHotkey.Interop
Public Class Form1
Public ahk = AutoHotkeyEngine.Instance
Public vbString As String = ""

Private Sub btnTest_Click(sender As Object, e As EventArgs) Handles btnTest.Click
    ahk.ExecRaw("MsgBox, Hello World, from AHK!")
    'programmatically set variables
    ahk.SetVar("x", "1")
    ahk.SetVar("y", "4")
    ahk.SetVar("ahkstr", "this value to be passed to .NET")
    vbString = ahk.GetVar("ahkstr")

    MessageBox.Show("From the AHK engine I got " & vbString)

    'execute statements

    'return variables back from ahk
    Dim zValue As Integer = ahk.GetVar("z")
    MessageBox.Show("Value of z is " & zValue.ToString) ' "Value of z is 5"

    End Sub

End Class

Can someone tell me how I might run essentially the same code in an AHK script that UiPath will accept, and how to pass the variables “ahkstr” and “z” to a UiPath MessageBox activity?



Hi all,

The examples I tried above in VB are of course not very useful. Is anyone willing to share an AutoHotKey script that you use with UiPath? I’d really be interested in any that communicate with the UiPath host workflow.

So far all my efforts at getting variables and arguments in or out of AutoHotkey to or from UiPath are coming up empty.

Thanks in advance,


I don’t have an answer but this would be cool to know.
I would check out the AutoHotkey forums for how to pass arguments; it’s been a while since I have looked in there. Looks like UiPath has a Results field and Parameters field that could be used with the AutoHotkey in and out arguments.


Some success, but it’s a kludge.
The attached files “HelloWorld.ahk” and “HelloFromAHK.xaml” are all that’s needed (I think).

  1. The AutoHotKey activity calls “HelloWorld.ahk”. An AHK message box displays a preassigned variable.

Hello World

  1. The AHK script writes the variable “myVar” to a text file in the script directory, called ‘myVar’, no extension, and then closes the file object and releases any locks. This last is just for safety.

  2. The UiPath Message Box takes “myVar” as an input variable and displays it.

AHK var passed to UiPath

In the real, non-beginner world, perhaps a more useful activity would be to have the AHK script write to a database or spreadsheet, and have the UiPath workflow retrieve it from there. AHK can do lots of things with databases and spreadsheets, and COM objects in general, so I think it would really be useful.

There is a mechanism described here for communicating with the hosting environment (i.e. UiPath in our case). I’m not a C-sharp programmer, and I haven’t had any luck with it. That looks to me like an expression-tree lambda, but I’m essentially clueless about that. If it is an expression tree, I’m going to try my luck with code described here, and I’ll post if I have any luck.

I have tried to use Invoke Code to communicate with the AutoHotkey instance, but I don’t yet know how to instantiate it so UiPath will see it. I remain hopeful.


Files (you’ll need to unzip to get HelloWorld.ahk) (543 Bytes)
HelloFromAHK.xaml (4.9 KB)