Code Monkey home page Code Monkey logo

autohotkey.interop's People

Contributors

amazing-andrew avatar lesomnus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autohotkey.interop's Issues

SendPipeMessage unreliable when used in a hotkey function

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

Wait for exit [QUESTION]

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");

Multithreading

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).

ExitApp

@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()

Interest in collaborating?

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]

Using 2 apps with AHK at the same time

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?

"RegClass" Error when creating an Instance

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.

  1. Create ahk = new AutoHotkey.Interop.AutoHotkeyEngine(); in the Window Load. Then call ExecRaw to execute some command.
  2. Open the Window.
  3. Close the Window.
  4. IMPORTANT: Open the window again very quickly (within 2-3 seconds)
    Outcome: There will be a dialog box with the Message "RegClass" and then the application will crash.

Hotkey not functioning

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.

Is it working for v2?

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!

"To use, just include my DLL and it will deploy any files that are missing if needed." - not working

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.

autohotkey interop error

The only differences I can see between my project and your example project is in the object browser.

Your example project looks like this:

autohotkey interop object browser-good

My project seems to be missing things:

autohotkey interop object browser-bad

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.

AccessViolation Exception in Desktop Bridged App

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:

  • Package WPF App
  • Install Autohotkey.Interop Nuget Package
  • Run the following code:
var ahk = AutoHotkeyEngine.Instance; 
ahk.LoadScript("Reload");

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.