amazing-andrew / autohotkey.interop Goto Github PK
View Code? Open in Web Editor NEWA wrapper to natively interact and embed autohotkey into your .net program.
License: GNU General Public License v2.0
A wrapper to natively interact and embed autohotkey into your .net program.
License: GNU General Public License v2.0
using AutoHotkey.Interop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace TestApp
{
class Program
{
static void Main(string[] args)
{
//grab a copy of the AutoHotkey singleton instance
var ahk = AutoHotkeyEngine.Instance;
var ipcHandler = new Func<string, string>(fromAhk =>
{
Console.WriteLine("received message from ahk " + fromAhk);
//System.Threading.Thread.Sleep(3000); //simulating lots of work
return ".NET: I LIKE PIE!";
});
//the initalize pipes module only needs to be called once per application
ahk.InitalizePipesModule(ipcHandler);
ahk.ExecRaw(@"
BindHotkey(hk, id){
fn := Func(""HkEvent"").Bind(id, ""1"")
hotkey, % hk, % fn
fn := Func(""HkEvent"").Bind(id, ""0"")
hotkey, % hk "" up"", % fn
}
HkEvent(id, state){
SendPipeMessage(""HK EVENT! ID = "" id "", State = "" state)
}
");
ahk.ExecRaw(@"BindHotkey(""F12"", ""999"")");
while (true)
{
Thread.Sleep(100);
}
}
}
}
Sometimes a runtime error is thrown ("Functions cannot contain functions")
Sometimes none of the hotkeys work
Hotkeys NEVER fire as often as they should (Spam F12 and you do not see a console log for each press / release)
If you have a release hotkey, after about the 5th press/release, all hotkeys stop firing
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");
Is it support Multithreading? I want check some variable with GetVar and do PixelSearch at the same time. I tried to create 2 ahk objects (AutoHotkeyEngine ahk
for GetVar andAutoHotkeyEngine sahk
for ExecRaw (PixelSearch) but I still can`t use them at the same time).
Hi
there is a way to disable the "original" message error ?
in AutoHotkey.exe i have /ErrorStdOut for disable the error message output
i would like intercept the error
is possible ?
@amazing-andrew
Every time I try to use ExitApp with ExecRaw I get an exception. Has anyone experienced this? The full text of the error is below.
System.AccessViolationException occurred
HResult=0x80004003
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=
StackTrace:
at AutoHotkey.Interop.AutoHotkeyDll.ahkExec(String code)
at AutoHotkey.Interop.AutoHotkeyEngine.ExecRaw(String code) in C:\Users\shepworth\Desktop\Cisco - better\ConsoleApplication1_R3\ConsoleApplication1_R1 - Copy\AutoHotkey.Interop-master\AutoHotkey.Interop-master\src\AutoHotkey.Interop\AutoHotkeyEngine.cs:line 84
at AutoHokey.UI.ViewModel.MainViewModel.OnLoadProgram(Object obj) in C:\Users\shepworth\Desktop\Cisco - better\ConsoleApplication1_R3\ConsoleApplication1_R1 - Copy\ConsoleApplication1\ConsoleApplication1\AutoHokey.UI\ViewModel\MainViewModel.cs:line 224
at Common.Utility.RelayCommand.Execute(Object parameter) in C:\Users\shepworth\Desktop\Cisco - better\ConsoleApplication1_R3\ConsoleApplication1_R1 - Copy\ConsoleApplication1\ConsoleApplication1\Common\Utility\RelayCommand.cs:line 27
at MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(ICommandSource commandSource, Boolean userInitiated)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at AutoHokey.UI.App.Main()
Hey Andrew, I've been working with your Interop to develop a DLL building off the original dll. The first release will contain all of the AHK commands wrapped in individual functions + includes Error Level info returned from AHK. I'm about 90% finished coding it, currently working to document. My goal is to test/develop that release to the point where it's ready to create a NuGet package to bring AHK into Visual Studio easily. I was just wondering if you had any interest in consulting / contributing to the effort? I'm still on the green side of coding but an avid AHK user looking for those functions in C#. So far so good :) Feel free to email me if interested - [email protected]
When I'm using 2 apps which are using AHK.Interop only 1 app that was launched first is working properly. In second app AHK functions are not working. How to fix it?
It is possible to use with VB6? How?
Thanks
I'm creating a new AHK instance at my WPF window load event. However, if I close the window and open the same window quickly, I get a dialog box with "RegClass" as the text. This only happens if I close and open the window quickly.
Recreation steps.
In my ahk script file I have put the hotstring example:
::btw::by the way
But nothing happens if I type them on a notepd. Same when run with AutoHotkey works.
I am trying to create a new instance of the AutoHotkeyEngine class using the AutoHotkeyVersion.v2 but my applications (C# .NET 4.7.2) throws a DllNotFoundException.
If I use the .Instance or the default constructor, the program works.
Do I need to do anything besides just installing the package to use v2?
Thanks!
So I'm attempting to implement your DLL which sounds easy but I cannot get it to work within my own c# .NET Winforms project.
I've downloaded your example solution and that is running just fine. It compiles, runs and works just as you'd expect.
I've try taking the DLL at this location:
AutoHotkey.Interop-master\AutoHotkey.Interop-master\src\AutoHotkey.Interop\bin\Debug\AutoHotkey.Interop.dll
and add that to my project. It adds just fine but when I try this line:
var ahk = AutoHotkey.Interop.AutoHotkeyEngine();
I get a compilation error that is attached. Please advise.
The only differences I can see between my project and your example project is in the object browser.
Your example project looks like this:
My project seems to be missing things:
I also went as far as adding your entire AutoHotkey.Interop proect to my project and referencing the project itself. That also did not work. Same compilation error.
I am using this Wrapper in a Desktop Bridge App , most of the functions work fine, but some are causing a non-catchable, deadly AccessViolation Exception.
These exceptions only happen if the app is "bridged"
Minimal reproducable example:
var ahk = AutoHotkeyEngine.Instance;
ahk.LoadScript("Reload");
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.