unit mtxmacro;
interface
uses windows, messages;

    function PlayInit (nMsg: integer): boolean; stdcall;
    function PlayStart: boolean; stdcall;
    function PlayIsActive: boolean; stdcall;

    procedure playKey (key: char; delay: longint); stdcall;
    procedure playAltKey (key: char; delay: longint);  stdcall;
    procedure playVirtKey (key: byte; comCtl, comShift, comAlt: boolean; delay: longint); stdcall;
    procedure playString (pch: pchar; delay: longint); stdcall;
    procedure playInsertKeyEvent (command: word; key: word;  delay: longint); stdcall;
    procedure keyboardClick (letra: char);
    procedure keyboardAlt (letra: char);

    procedure playMouse (command, x, y: word; delay: longint);  stdcall;
    procedure mouseClick (x, y: integer);
    procedure mouseDoubleClick (x, y: integer);
    procedure mouseBeginDrag (x, y: integer);
    procedure mouseContinueDrag (x, y: integer);
    procedure mouseEndDrag (x, y: integer);

implementation

function PlayInit (nMsg: integer): boolean;
                stdcall; external 'MKBMOUSE' name 'PLAYINIT';
function PlayStart: boolean;
                stdcall; external 'MKBMOUSE' name 'PLAYSTART';
function PlayIsActive: boolean;
                stdcall; external 'MKBMOUSE' name 'PLAYISACTIVE';
procedure playKey (key: char; delay: longint);
                stdcall; external 'MKBMOUSE' name 'PLAYKEY';
procedure playAltKey (key: char; delay: longint);
                stdcall; external 'MKBMOUSE' name 'PLAYALTKEY';
procedure playVirtKey (key: byte; comCtl, comShift, comAlt: boolean; delay: longint);
                stdcall; external 'MKBMOUSE' name 'PLAYVIRTKEY';
procedure playString (pch: pchar; delay: longint);
                stdcall; external 'MKBMOUSE' name 'PLAYSTRING';
procedure playInsertKeyEvent (command: word; key: word;  delay: longint);
                stdcall; external 'MKBMOUSE' name 'PLAYINSERTKEYEVENT';
procedure playMouse (command, x, y: word; delay: longint);
                stdcall; external 'MKBMOUSE' name 'PLAYMOUSE';

procedure keyboardClick (letra: char);
var
    codLetra: longint;
begin
    codLetra := longint(oemKeyScan (ord(letra)) and $ffff) shl 8 +
                  vkKeyScan (letra);

    playInit (30);
    playInsertKeyEvent (WM_KEYDOWN, codLetra, 1);
    playStart;
    while  playIsActive do;

    playInit (30);
    playInsertKeyEvent (WM_KEYUP, codLetra, 1);
    playStart;
    while  playIsActive do;
end;

procedure keyboardAlt (letra: char);
begin
    playInit (30);
    playAltKey (letra, 1);
    playStart;
    while  playIsActive do;
end;

procedure mouseClick (x, y: integer);
begin
    playInit (30);
    playMouse (WM_MOUSEMOVE, x, y, 1);
    playStart;
    while  playIsActive do;

    playInit (30);
    playMouse (WM_LBUTTONDOWN, x, y, 1);
    playStart;
    while  playIsActive do;

    playInit (30);
    playMouse (WM_LBUTTONUP, x, y, 1);
    playStart;
    while  playIsActive do;
end;

procedure mouseDoubleClick (x, y: integer);
begin
    playInit (30);
    playMouse (WM_LBUTTONDOWN, x, y, 50);
    playMouse (WM_LBUTTONUP, x, y, 50);
    playMouse (WM_LBUTTONDOWN, x, y, 50);
    playMouse (WM_LBUTTONUP, x, y, 50);
    playMouse (WM_LBUTTONDBLCLK, x, y, 50);
    playstart;
    while playIsActive do;
end;

procedure mouseBeginDrag (x, y: integer);
begin
    playInit (30);
    playMouse (WM_LBUTTONDOWN, x, y, 50);
    playstart;
    while playIsActive do;
end;

procedure mouseContinueDrag (x, y: integer);
begin
    playInit (30);
    playMouse (WM_MOUSEMOVE, x, y, 50);
    playstart;
    while playIsActive do;
end;

procedure mouseEndDrag (x, y: integer);
begin
    playInit (30);
    playMouse (WM_LBUTTONUP, x, y, 1);
    playstart;
    while playIsActive do;
end;

end.