Code:
library KeySend;
uses
Windows,
Messages,
SysUtils,
Variants,
Classes,
Graphics,
Controls,
Forms,
Dialogs;
{$R *.res}
function GetHandle(Titel: PChar): HWnd;
var wnd: HWnd;
begin
wnd := FindWindow(nil, Titel);
if wnd = 0 then
wnd := FindWindow(Titel, nil);
if wnd = 0 then
ShowMessage ('Handle nicht gefunden!');
wnd := FindWindow(nil, Titel);
if wnd <> 0 then
Result := wnd;
end;
procedure SendKey(Handle: HWnd; key: PChar; const shift: TShiftState;
const specialkey: Boolean);
type
TBuffers = array [0..1] of TKeyboardState;
var
pKeyBuffers: ^TBuffers;
lParam: LongInt;
Taste: Word;
begin
Taste := Word(Key);
if IsWindow(Handle) then
begin
pKeyBuffers := nil;
lParam := MakeLong(0, MapVirtualKey(Ord(Taste), 0));
if specialkey then
lParam := lParam or $1000000;
New(pKeyBuffers);
try
GetKeyboardState(pKeyBuffers^[1]);
FillChar(pKeyBuffers^[0], SizeOf(TKeyboardState), 0);
if ssShift in shift then
pKeyBuffers^[0][VK_SHIFT] := $80;
if ssAlt in shift then
begin
pKeyBuffers^[0][VK_MENU] := $80;
lParam := lParam or $20000000;
end;
if ssCtrl in shift then
pKeyBuffers^[0][VK_CONTROL] := $80;
if ssLeft in shift then
pKeyBuffers^[0][VK_LBUTTON] := $80;
if ssRight in shift then
pKeyBuffers^[0][VK_RBUTTON] := $80;
if ssMiddle in shift then
pKeyBuffers^[0][VK_MBUTTON] := $80;
SetKeyboardState(pKeyBuffers^[0]);
if ssAlt in Shift then
begin
PostMessage(Handle, WM_SYSKEYDOWN, Ord(Taste), lParam);
PostMessage(Handle, WM_SYSKEYUP, Ord(Taste), lParam or $C0000000);
end
else
begin
PostMessage(Handle, WM_KEYDOWN, Ord(Taste), lParam);
PostMessage(Handle, WM_KEYUP, Ord(Taste), lParam or $C0000000);
end;
Application.ProcessMessages;
SetKeyboardState(pKeyBuffers^[1]);
finally
if pKeyBuffers <> nil then
Dispose(pKeyBuffers);
end; { If }
end;
end; { PostKeyEx }
exports
SendKey index 1,
GetHandle index 2;
begin
ShowMessage ('By General Desert');
end.