Harald wrote:
> TForm1.FormActivate bliver kun kaldt 1 gang og det er når programmet
> startes, hvis du vil have et kald hver gang programmet bringes i front så
> brug Application.OnActivate.
Mange tak!
Det løste mit problem :)
Jeg har nu en færdig simpel open-source auto-clicker :)
For dem der er interesseret, er source og object definition her:
==========
Main.dfm
----------
object frmMain: TfrmMain
Left = 192
Top = 114
Width = 257
Height = 243
BorderIcons = [biSystemMenu]
Caption = 'Autoclicker'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object ScrollBox1: TScrollBox
Left = 9
Top = 23
Width = 231
Height = 177
Align = alClient
BevelInner = bvNone
BevelOuter = bvNone
BorderStyle = bsNone
TabOrder = 0
object GroupBox1: TGroupBox
Left = 8
Top = 8
Width = 217
Height = 49
Caption = 'Antal millisekunder mellem klik'
TabOrder = 0
object SpinEdit1: TSpinEdit
Left = 8
Top = 16
Width = 201
Height = 22
Increment = 50
MaxValue = 2147483647
MinValue = 100
TabOrder = 0
Value = 1100
OnChange = SpinEdit1Change
end
end
object GroupBox2: TGroupBox
Left = 8
Top = 64
Width = 217
Height = 49
Caption = 'Automatisk afvigelse'
TabOrder = 1
object SpinEdit2: TSpinEdit
Left = 8
Top = 16
Width = 201
Height = 22
Increment = 50
MaxValue = 2147483647
MinValue = 0
TabOrder = 0
Value = 50
end
end
object GroupBox3: TGroupBox
Left = 8
Top = 120
Width = 217
Height = 49
Caption = 'Aktiveret? (N'#229'r program ikke har fokus)'
TabOrder = 2
object chkActive: TCheckBox
Left = 8
Top = 16
Width = 201
Height = 25
Caption = 'Ja da!'
Checked = True
State = cbChecked
TabOrder = 0
end
end
end
object TBDock1: TTBDock
Left = 0
Top = 0
Width = 249
Height = 23
object TBToolbar1: TTBToolbar
Left = 0
Top = 0
Caption = 'TBToolbar1'
TabOrder = 0
object TBSubmenuItem1: TTBSubmenuItem
Caption = 'Menu'
object TBItem1: TTBItem
Caption = 'Hj'#230'lp'
OnClick = TBItem1Click
end
object TBSeparatorItem1: TTBSeparatorItem
end
object TBItem2: TTBItem
Caption = 'Afslut'
OnClick = TBItem2Click
end
end
end
end
object TBDock2: TTBDock
Left = 0
Top = 200
Width = 249
Height = 9
Position = dpBottom
end
object TBDock3: TTBDock
Left = 0
Top = 23
Width = 9
Height = 177
Position = dpLeft
end
object TBDock4: TTBDock
Left = 240
Top = 23
Width = 9
Height = 177
Position = dpRight
end
object Timer1: TTimer
Enabled = False
Interval = 1100
OnTimer = Timer1Timer
Top = 72
end
end
==========
Main.pas
----------
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, ExtCtrls, StdCtrls, Spin, TB2Item, TB2Dock, TB2Toolbar, Help;
type
TfrmMain = class(TForm)
ScrollBox1: TScrollBox;
GroupBox1: TGroupBox;
SpinEdit1: TSpinEdit;
GroupBox2: TGroupBox;
SpinEdit2: TSpinEdit;
Timer1: TTimer;
TBDock1: TTBDock;
TBDock2: TTBDock;
TBDock3: TTBDock;
TBDock4: TTBDock;
TBToolbar1: TTBToolbar;
TBSubmenuItem1: TTBSubmenuItem;
TBItem1: TTBItem;
TBSeparatorItem1: TTBSeparatorItem;
TBItem2: TTBItem;
GroupBox3: TGroupBox;
chkActive: TCheckBox;
procedure Timer1Timer(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormDeactivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SpinEdit1Change(Sender: TObject);
procedure TBItem2Click(Sender: TObject);
procedure TBItem1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
function IIf(Expression: Boolean; TruePart: Integer; FalsePart:
Integer): Integer;
implementation
{$R *.dfm}
function IIf(Expression: Boolean; TruePart: Integer; FalsePart:
Integer): Integer;
begin
If Expression Then
Result := TruePart
Else
Result := FalsePart;
end;
procedure TfrmMain.Timer1Timer(Sender: TObject);
var
Pt : TPoint;
begin
Application.ProcessMessages;
GetCursorPos(pt);
Pt := ClientToScreen(Pt);
Pt.x := Round(Pt.x * (65535 / Screen.Width));
Pt.y := Round(Pt.y * (65535 / Screen.Height));
Mouse_Event(MOUSEEVENTF_ABSOLUTE or
MOUSEEVENTF_LEFTDOWN,
Pt.x, Pt.y, 0, 0);;
Mouse_Event(MOUSEEVENTF_ABSOLUTE or
MOUSEEVENTF_LEFTUP,
Pt.x, Pt.y, 0, 0);;
If Sender Is TTimer Then
(Sender As TTimer).Interval := SpinEdit1.Value - SpinEdit2.Value +
Random(SpinEdit2.Value * 2);
end;
procedure TfrmMain.FormActivate(Sender: TObject);
begin
Timer1.Enabled := False;
end;
procedure TfrmMain.FormDeactivate(Sender: TObject);
begin
Timer1.Enabled := True And chkActive.Checked;
end;
procedure TfrmMain.FormCreate(Sender: TObject);
begin
Randomize;
SpinEdit1.Value := Timer1.Interval;
Application.OnActivate := FormActivate;
Application.OnDeactivate := FormDeactivate;
With Self Do Begin
ClientWidth := 233;
ClientHeight := 200;
End;
end;
procedure TfrmMain.SpinEdit1Change(Sender: TObject);
begin
If Sender Is TSpinEdit Then
Timer1.Interval := (Sender As TSpinEdit).Value - SpinEdit2.Value +
Random(SpinEdit2.Value * 2);
end;
procedure TfrmMain.TBItem2Click(Sender: TObject);
begin
Close;
end;
procedure TfrmMain.TBItem1Click(Sender: TObject);
begin
frmHelp.ShowModal;
end;
end.
==========
Help.dfm
----------
object frmHelp: TfrmHelp
Left = 192
Top = 114
Width = 870
Height = 640
Caption = 'Hj'#230'lp til autoclicker'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object ScrollBox1: TScrollBox
Left = 0
Top = 0
Width = 862
Height = 606
Align = alClient
BevelInner = bvNone
BevelOuter = bvNone
BorderStyle = bsNone
TabOrder = 0
object RichEdit1: TRichEdit
Left = 0
Top = 0
Width = 862
Height = 606
Align = alClient
BevelInner = bvNone
BevelOuter = bvNone
BorderStyle = bsNone
Color = clBtnFace
ReadOnly = True
TabOrder = 0
end
end
end
==========
Help.pas
----------
unit Help;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, StdCtrls, ComCtrls;
type
TfrmHelp = class(TForm)
ScrollBox1: TScrollBox;
RichEdit1: TRichEdit;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmHelp: TfrmHelp;
implementation
{$R *.dfm}
procedure TfrmHelp.FormCreate(Sender: TObject);
begin
RichEdit1.Text :=
'{\rtf1\ansi\ansicpg1252\deff0\deflang1030{\fonttbl{' +
'\f0\fswiss\fprq2\fcharset0'+ 'Tahoma;}{\f1\fswiss\fprq2\fcharset0
Trebuchet ' + 'MS;}{\f2\fswiss\fcharset0'+' Arial;}}' + #13#10 +
'{\*\generator Msftedit 5.41.15.1503;}\viewkind4\uc1\pard\b\f0\fs40 ' +
'Autoclicker hj\''e6lp\par' +
'\b0\f1\fs20\par' + #13#10 +
'Autoclicker er et meget simpelt program, som styres s\''e5ledes:\par' +
#13#10 + '1) Start programmet *DUH*.\par' + #13#10 +
'2) Indstil indstillingerne. \par' + #13#10 +
'3) Ryk programmets hovedvindue, s\''e5 du kan se det omr\''e5de hvor '
+ 'der skal autoclickes.\par' + #13#10 +
'4) Flyt musen derhen hvor der skal autoclickes.\par' + #13#10 +
'5) Venstre klik med musen \''e9n gang, s\''e5 autoclickeren starter ' +
'autoclickningen.\par' + #13#10 +
'6) N\''e5r du vil afbryde autoclickningen, hold Alt inde og tryk ' +
'p\''e5 Tab.\f2\par' + #13#10 +
'}''';
With Self Do Begin
ClientWidth := 512;
ClientHeight := 184;
End;
end;
end.
------------
EO project
============
Help.pas' TfrmHelp.FormCreate blev lidt rodet, men det er desværre pga.
at newsgroups deler linier efter 72 tegn. Det er dog testet efter
linieombrydningen, og skulle gerne virke :)
--
Mvh. Mathias | @: mathias *der* *bor* *på* mrside *i* dk 1
http://www.vitoo.dk/ - alle tiders community site 2
1234567890123456789012345678901234567890123456789012345678901234567890 3