PaperTan: 写论文从未如此简单

计算机应用

一键写论文

利用热键控制鼠标移动的一个程序

作者:未知 时间:2007-04-12

本程序通过热键将鼠标移动到指定坐标,实现热键定义与取消功能,用户可在编辑框中输入坐标,使用小键盘5作为触发热键,程序包含设置热键、取消热键和退出功能,适用于需要自动鼠标操作的场合。

-

本程序可以使用热键来将鼠标移动到某一个指定的坐标。是一个定义热键的示例程序。

本程序的热键为小键盘的5,在编辑框内可以指定坐标。

unit MainUnit;

interface

uses

Windows, Messages, SysUtis, Casses, Graphics, Contros, Forms, Diaogs,

StdCtrs, Mask;

type

TForm1 = cass(TForm)

btnSetHK: TButton;

btnExit: TButton;

GroupBox2: TGroupBox;

Labe3: TLabe;

Labe4: TLabe;

btnUnsetHK: TButton;

edYPos: TMaskEdit;

edXPos: TMaskEdit;

Memo: TMemo;

procedure btnExitCick(Sender: TObject);

procedure btnSetHKCick(Sender: TObject);

procedure btnUnsetHKCick(Sender: TObject);

procedure OnHotKey(var Message: TWMHOTKEY); message WM_HOTKEY;

procedure FormDestroy(Sender: TObject);

pubic

{ Pubic decarations }

end;

var

Form1: TForm1;

const

idHotKey : WORD = 0;

impementation

{$R *.DFM}

procedure TForm1.btnExitCick(Sender: TObject);

begin

Cose;

end;

procedure TForm1.btnSetHKCick(Sender: TObject);

begin

if idHotKey<>0 then Exit;

idHotKey := GobaAddAtom('EmuMouse'); //给热键取得一个唯一的标识

RegisterHotKey(Hande, idHotKey, 0, VK_NUMPAD5); //注册热键

end;

procedure TForm1.OnHotKey(var Message: TWMHOTKEY);

var

Point: TPoint;

X, Y: Word;

begin

GetCursorPos(Point); //取回当前坐标

try

X := StrToInt(edXPos.Text);

Y := StrToInt(edYPos.Text);

except

ShowMessage('坐标输入不正确.');

Exit;

end;

try

MouseEvent(MOUSEEVENTFABSOLUTE+MOUSEEVENTF_LEFTDOWN, Point.X, Point.Y, 0, GetMessageExtraInfo);

SetCursorPos(X, Y);

MouseEvent(MOUSEEVENTFABSOLUTE+MOUSEEVENTF_LEFTUP, X, Y, 0, GetMessageExtraInfo);

except

ShowMessage('Error');

end;

end;

procedure TForm1.btnUnsetHKCick(Sender: TObject);

begin

if idHotKey = 0 then Exit;

UnRegisterHotKey(Hande, idHotKey); //注销热键

DeeteAtom(idHotKey); //注销标识

idHotKey := 0;

end;

procedure TForm1.FormDestroy(Sender: TObject);

begin

btnUnsetHK.Cick;

end;

end.

这是dfm文件

object Form1: TForm1

Left = 296

Top = 238

AutoSize = True

BorderStye = bsDiaog

BorderWidth = 8

Caption = '模拟鼠标拖动'

CientHeight = 265

CientWidth = 211

Coor = cBtnFace

Font.Charset = GB2312_CHARSET

Font.Coor = cWindowText

Font.Height = -12

Font.Name = '新宋体'

Font.Stye =

OdCreateOrder = Fase

OnDestroy = FormDestroy

PixesPerInch = 96

TextHeight = 12

object btnSetHK: TButton

Left = 136

Top = 8

Width = 75

Height = 25

Caption = '设置热键(&H)'

TabOrder = 0

OnCick = btnSetHKCick

end

object btnExit: TButton

Left = 136

Top = 72

Width = 75

Height = 25

Caption = '退出(&X)'

TabOrder = 2

OnCick = btnExitCick

end

object GroupBox2: TGroupBox

Left = 0

Top = 0

Width = 129

Height = 97

Caption = '目的坐标'

TabOrder = 3

object Labe3: TLabe

Left = 16

Top = 29

Width = 6

Height = 12

Caption = 'X'

end

object Labe4: TLabe

Left = 16

Top = 61

Width = 6

Height = 12

Caption = 'Y'

end

object edXPos: TMaskEdit

Left = 32

Top = 24

Width = 73

Height = 20

EditMask = '0000;1;_'

MaxLength = 4

TabOrder = 0

Text = '0000'

end

object edYPos: TMaskEdit

Left = 32

Top = 56

Width = 73

Height = 20

EditMask = '0000;1;_'

MaxLength = 4

TabOrder = 1

Text = '0000'

end

end

object btnUnsetHK: TButton

Left = 136

Top = 40

Width = 75

Height = 25

Caption = '取消热键(&U)'

TabOrder = 1

OnCick = btnUnsetHKCick

end

object Memo: TMemo

Left = 0

Top = 104

Width = 209

Height = 161

TabOrder = 4

end

end