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:
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("ahkstr", "this value to be passed to .NET")
vbString = ahk.GetVar("ahkstr")
MessageBox.Show("From the AHK engine I got " & vbString)
'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"
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?
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.
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).
The AutoHotKey activity calls “HelloWorld.ahk”. An AHK message box displays a preassigned variable.
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.
The UiPath Message Box takes “myVar” as an input variable and displays it.
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.
Two things can happen after you then restart the Studio with your project.
It will either show your import already on the list
it will show it on the list with an error. In this case we will need to investigate further, but the most likely solution might have to be an update of your Studio.