unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 =
class(TForm)
Timer1: TTimer;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
DCFarbe: TColor;
DesktopDC: hDC;
implementation
{$R *.dfm}
function ColorToleranz(SollColor, IstColor: TColor; Toleranz: Byte): boolean;
var
rSoll, gSoll, bSoll, rIst, gIst, bIst: byte;
begin
Result:= false;
SollColor := ColorToRgb(SollColor);
rSoll := GetRvalue(SollColor);
gSoll := GetGvalue(SollColor);
bSoll := GetBvalue(SollColor);
IstColor := ColorToRgb(IstColor);
rIst := GetRvalue(IstColor);
gIst := GetGvalue(IstColor);
bIst := GetBvalue(IstColor);
if (rIst >= rSoll- Toleranz)
and (rIst <= rSoll + Toleranz)
and
(gIst >= gSoll- Toleranz)
and (gIst <= gSoll + Toleranz)
and
(bIst >= bSoll- Toleranz)
and (bIst <= bSoll + Toleranz)
then
Result := true;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DesktopDC := GetDC(0);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
DCFarbe := GetPixel(DesktopDC, Mouse.CursorPos.X, Mouse.CursorPos.Y);
if ColorToleranz(clBlack, DCFarbe, 1)
then//max 255
begin
mouse_event(MOUSEEVENTF_LEFTDOWN, Mouse.CursorPos.X, Mouse.CursorPos.Y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, Mouse.CursorPos.X, Mouse.CursorPos.Y, 0, 0);
end;
end;
end.