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.