📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ComCtrls,Registry,inifiles, ExtCtrls;
type
TForm1 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
CheckBox1: TCheckBox;
Button1: TButton;
Button2: TButton;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Edit1: TEdit;
Label1: TLabel;
Button3: TButton;
TabSheet3: TTabSheet;
CheckBox2: TCheckBox;
Label2: TLabel;
Button5: TButton;
Label4: TLabel;
GroupBox3: TGroupBox;
GroupBox4: TGroupBox;
CheckBox3: TCheckBox;
GroupBox5: TGroupBox;
Label3: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
tmrSetCpos: TTimer;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure CheckBox1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure tmrSetCposTimer(Sender: TObject);
private
{ Private declarations }
id,id2,id3,id4:atom; //hotkey的id
procedure hotkey(var msg:tmessage);message wm_hotkey;
public
{ Public declarations }
end;
var
Form1: TForm1;
//Myvar
cposX,cposY:integer;
P:TPoint;
LockRect,FreeRect: TRect;
implementation
{$R *.dfm}
uses unit2;
var thread1:MOUSESIMU;
state:bool=false;
IniFile:TIniFile;
atom:integer;
procedure MyCursorPos();
begin
//取得鼠标位置
getcursorpos(p);
cposX:=p.x;
cposY:=p.Y;
end;
procedure LockCursorPos();
begin
if state then
begin
LockRect := Rect(cposx,cposY,1,1);
ClipCursor(@LockRect);
end;
end;
procedure UnLockCursorPos();
begin
if state=false then
begin
FreeRect := Rect(0,0,Screen.Width,Screen.Height);
ClipCursor(@FreeRect);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var delay:integer;
begin
MyCursorPos();//鼠标坐标
stop:=false;
if checkbox2.Checked then
self.Hide;
delay:=strtoint(edit1.Text);
thread1:=MOUSESIMU.create(false);
if RadioButton1.Checked then
thread1.state:=1;
if RadioButton2.Checked then //设置击键类型
thread1.state:=2;
if RadioButton3.Checked then
thread1.state:=3;
thread1.delay:= delay;
if state=false then
begin
state:=true;
//LockCursorPos();//锁定鼠标
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if state then
begin
stop:=true;
state:=false ;
//UnLockCursorPos();//解锁
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
Reg:TRegistry;
begin
Reg:=TRegistry.Create;
reg.RootKey:=HKEY_LOCAL_MACHINE;
if CheckBox1.Checked then
begin
if reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run',True)then
reg.WriteString('mousesim',application.ExeName);
end else
begin
if reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run',false) then
if reg.ValueExists('mousesim') then
reg.DeleteValue('mousesim');
end;
IniFile:=TIniFile.Create(ExtractFilePath(Application.Exename)+'my_config.ini');
if CheckBox2.Checked then
IniFile.WriteInteger('setting','hide',1) else
IniFile.WriteInteger('setting','hide',0);
if CheckBox3.Checked then
IniFile.WriteInteger('setting','autostart',1) else
IniFile.WriteInteger('setting','autostart',0);
Reg.CloseKey;
Reg.Free;
IniFile.Free;
application.MessageBox('设置成功!','提示');
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
IniFile:=TIniFile.Create( ExtractFilePath(Application.Exename)+'my_config.ini');
if RadioButton1.Checked then
IniFile.WriteInteger('funtion','setstyle',1)
else if RadioButton2.Checked then
IniFile.WriteInteger('funtion','setstyle',2) else
IniFile.WriteInteger('funtion','setstyle',3);
IniFile.WriteInteger('funtion','speed',strtoint(edit1.Text));
application.MessageBox('保存成功!','提示')
end;
procedure TForm1.FormCreate(Sender: TObject);
var i,position:integer;
s:string;
Reg:TRegistry;
begin
//检查程序是否在运行
{如果没运行则在表中增加信息 }
if GlobalFindAtom('PROGRAM_RUNNING') = 0 then
atom := GlobalAddAtom('PROGRAM_RUNNING')
else begin
{如果程序已运行则显示信息然后退出 }
MessageDlg('程序已经在运行,如果没有显示,请按F8键!',mtWarning,[mbOK],0);
Halt;
end;
//程序读取ini文件初始化
reg:=TRegistry.Create;
reg.RootKey:=HKEY_LOCAL_MACHINE;
if reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run\',True) then
begin
s:=reg.ReadString('mousesim');
if s='' then
CheckBox1.Checked:=false else
CheckBox1.Checked:=true;
end ;
IniFile:=TIniFile.Create(ExtractFilePath(Application.Exename)+'my_config.ini');
i:=IniFile.ReadInteger('funtion','setstyle',1);
if i=1 then
RadioButton1.Checked:=true else
if i=2 then
RadioButton2.Checked:=true else
if i=3 then
RadioButton3.Checked:=true ;
i:=IniFile.ReadInteger('funtion','speed',500);
edit1.Text:=inttostr(i);
i:=IniFile.ReadInteger('setting','autostart',0);
if i=1 then
begin
CheckBox3.Checked:=true;
self.Button1Click(sender);
end;
i:=IniFile.ReadInteger('setting','hide',0);
if i=1 then
begin
CheckBox2.Checked:=true;
end;
if CheckBox1.Checked then
CheckBox3.Enabled:=true;
IniFile.Free;
//定义hotkey
id:=globaladdatom('hot key');
id2:=globaladdatom('hot key2');
id3:=globaladdatom('hot key3');
id4:=globaladdatom('hot key4');
RegisterHotKey(handle,id,0,vk_f7);
RegisterHotKey(handle,id2,0,vk_f5);
RegisterHotKey(handle,id3,0,vk_f6);
RegisterHotKey(handle,id4,0,vk_f8);
end;
procedure TForm1.hotkey(var msg:tmessage);
var Sender: TObject;
begin
if msg.LParamHi=VK_F6 then
self.Button2Click(Sender);
if msg.LParamHi=VK_F8 then
self.Show;
if (msg.LParamHi=VK_F7) then
self.Hide;
if msg.LParamHi=VK_F5 then
self.Button1Click(Sender);
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
If not (key in [#48..#57,#8]) then //#8是退格键,也可以加上#13回车键
begin
application.MessageBox('只能输入数字!','提示');
key:= #0;
end;
end;
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
if CheckBox1.Checked then
CheckBox3.Enabled:=true
else
begin
CheckBox3.Checked:=false;
CheckBox3.Enabled:=false;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
UnRegisterHotKey(handle,id);
UnRegisterHotKey(handle,id2);
UnRegisterHotKey(handle,id3);
UnRegisterHotKey(handle,id4);
GlobalDeleteAtom(atom);
end;
procedure TForm1.tmrSetCposTimer(Sender: TObject);
begin
if state then
begin
setcursorpos(cposX,cposY);//锁定鼠标位置
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -