----------Unit
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Timer1: TTimer;
Edit4: TEdit;
procedure ListBox1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ListBox1Click(Sender: TObject);
begin
Edit1.Text:=ListBox1.Items[ ListBox1.ItemIndex];
end;
procedure TForm1.Button1Click(Sender: TObject);
var
oldPoint,newPoint:TPOINT;
p: TPoint;
begin
p.X := ListBox1.left+5;
p.Y := ListBox1.top+3;
p := ClientToScreen(p);
SetCursorPos(p.X,p.Y);
//ListBox1.SetFocus ;
GetCursorPos(oldPoint); //保存当前鼠标bai位置。
//SetCursorPos(619,401);//SetCursorPos(oldPoint.x+5,oldPoint.y+5);
Edit2.Text:='X: '+inttostr(oldPoint.x)+' Y: '+inttostr(oldPoint.y);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);//模拟按下鼠标左键。
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);//模拟放开鼠标左键。
GetCursorPos(NewPoint);
Edit3.Text:='X: '+inttostr(NewPoint.x)+' Y: '+inttostr(NewPoint.y);
//SetCursorPos(oldPoint.x,oldPoint.y);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
newPoint:TPOINT;
begin
GetCursorPos(NewPoint);
Form1.Caption:='Form1 '+'X: '+inttostr(NewPoint.x)+' Y: '+inttostr(NewPoint.y);
end;
end.
------------Form
object Form1: TForm1
Left = 594
Top = 366
Width = 476
Height = 244
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object ListBox1: TListBox
Left = 0
Top = 0
Width = 169
Height = 145
ImeName = '中文(简体) - 搜狗拼音输入法'
ItemHeight = 13
Items.Strings = (
'1111111111'
'2222222222')
TabOrder = 0
OnClick = ListBox1Click
end
object Button1: TButton
Left = 232
Top = 128
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
object Edit1: TEdit
Left = 8
Top = 152
Width = 121
Height = 21
ImeName = '中文(简体) - 搜狗拼音输入法'
TabOrder = 2
Text = 'Edit1'
end
object Edit2: TEdit
Left = 200
Top = 8
Width = 121
Height = 21
ImeName = '中文(简体) - 搜狗拼音输入法'
TabOrder = 3
Text = 'Edit2'
end
object Edit3: TEdit
Left = 200
Top = 48
Width = 121
Height = 21
ImeName = '中文(简体) - 搜狗拼音输入法'
TabOrder = 4
Text = 'Edit3'
end
object Edit4: TEdit
Left = 200
Top = 88
Width = 121
Height = 21
ImeName = '中文(简体) - 搜狗拼音输入法'
TabOrder = 5
Text = 'Edit4'
end
object Timer1: TTimer
Interval = 100
OnTimer = Timer1Timer
Left = 376
Top = 96
end
end
--------------------------------------------------相关
mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);//模拟按下鼠标右键。
mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);//模拟放开鼠标右键。
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);//模拟按下鼠标左键。
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);//模拟放开鼠标左键。
keybd_event(VK_SHIFT,MapVirtualKey(VK_SHIFT,0),0,0); //按下SHIFT键。
keybd_event(0x52,MapVirtualKey(0x52,0),0,0);//按下R键。
keybd_event(0x52,MapVirtualKey(0x52,0),KEYEVENTF_KEYUP,0);//放开R键。
keybd_event(VK_SHIFT,MapVirtualKey(VK_SHIFT,0),KEYEVENTF_KEYUP,0);//放开SHIFT键。