[v2] calling autohotkey.dll from Delphi

Ask for help, how to use AHK_H, etc.
jimsweb
Posts: 4
Joined: 11 May 2022, 01:00

[v2] calling autohotkey.dll from Delphi

Post by jimsweb » 11 May 2022, 01:15

This is my very first post - please be mild on me...
I have been trying to run ahk scripts via AutoHotkey.dll (from https://hotkeyit.github.io/v2/) using Delphi. Following is my sample code.. it compiles just fine, however it doesn't produce the desired output.. any help, or direction is highly appreciated.

Code: Select all

unit Unit1;
interface
uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TexecScript = function(script: string): integer; cdecl;

var
  Form1: TForm1;
  ahkExec: TexecScript;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  handle: THandle;
begin
  handle := LoadLibrary('AutoHotkey.dll');
  // If succesful ...
  if handle <> 0 then
  begin
    if handle >= 32 then { success }
    begin
      ahkExec := GetProcAddress(handle, 'ahkExec');
      ahkExec('MsgBox ''Hello World!''');
    end
    else
      MessageDlg('Error: could not find AutoHotkey.DLL', mtError, [mbOk], 0);
    // FreeLibrary(Handle);
  end;
end;
end.
Last edited by gregster on 11 May 2022, 01:17, edited 1 time in total.
Reason: Topic moved to 'AutoHotkey_H Help'.

jimsweb
Posts: 4
Joined: 11 May 2022, 01:00

Re: [v2] calling autohotkey.dll from Delphi

Post by jimsweb » 14 May 2022, 10:34

@HotKeyIt can you please comment?

User avatar
thqby
Posts: 397
Joined: 16 Apr 2021, 11:18
Contact:

Re: [v2] calling autohotkey.dll from Delphi

Post by thqby » 14 May 2022, 11:10

Code: Select all

threadid := NewThread(script)
ahkExec('MsgBox', threadid)

newvice
Posts: 24
Joined: 12 Jun 2021, 09:20

Re: [v2] calling autohotkey.dll from Delphi

Post by newvice » 23 Aug 2022, 15:30

did you make any progress? Im trying to get the v2 to run in powershell/.net and I had no luck. Share your full code please I want to see how the thread thing works and how the dll invokes look.

jimsweb
Posts: 4
Joined: 11 May 2022, 01:00

Re: [v2] calling autohotkey.dll from Delphi

Post by jimsweb » 23 Aug 2022, 15:52

It never worked for me unfortunately and I moved ahead by using another product which does work. :-)

Post Reply

Return to “Ask for Help”