amazing-andrew / AutoHotkey.Interop

A wrapper to natively interact and embed autohotkey into your .net program.
GNU General Public License v2.0
187 stars 55 forks source link

Wait for exit [QUESTION] #1

Closed jaywick closed 9 years ago

jaywick commented 9 years ago

Is there way to wait for the script to exit before returning control back to C#. Either via callback or blocking call?

For example

MessageBox.Show("This is run before user pressed Alt + X");
await ahk.ExecRawAsync("!x::MsgBox, Alt X was pressed and caught by AHK Engine");
MessageBox.Show("This is run after user pressed Alt + X");
amazing-andrew commented 9 years ago

Autohotkey will Block by giving the code you want to run instead of setting up a hotkey.

ahk.ExecRaw("MsgBox, This message will block until you press OK.");

However, from your example code it looks like you want to use a callback. There currently isn't a way for this library to provide callbacks from AHK back into .NET.

I've researched this for a while and found one solution, Which would be setting up IPC between the .net and AHK via named pipes. It doesn't look pretty. But it would work by having the C# program create a named pipe server and then have autohotkey connect as a client and send messages to the named pipe.

Here is a link that might help you get started. http://www.autohotkey.com/board/topic/103403-ipc-using-named-pipes/

Hope this helps! ~Andrew

jaywick commented 9 years ago

You're right @amazing-andrew , it appears IPC is the only way. I wasn't aware Autohotkey would play well with named pipes! Thanks for the link :+1: