利用热键控制鼠标移动的程序研究论文本程序可以使用热键来将鼠标移动到某一个指定的坐标。是一个定义热键的示例程序。本程序的热键为小键盘的5,在编辑框内可以指定坐标。unitMainUnit;interfaceusesWindows,Messages,SysUtils,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls,Mask;typeTForm1=class(TForm)btnSetHK:TButton;btnExit:TButton;GroupBox2:TGroupBox;Label3:TLabel;Label4:TLabel;btnUnsetHK:TButton;edYPos:TMaskEdit;e邓小平os:TMaskEdit;Memo:TMemo;procedurebtnExitClick(Sender:TObject);procedurebtnSetHKClick(Sender:TObject);procedurebtnUnsetHKClick(Sender:TObject);procedureOnHotKey(varMessage:TWMHOTKEY);messageWM_HOTKEY;procedureFormDestroy(Sender:TObject);public{Publicdeclarations}end;varForm1:TForm1;constidHotKey:WORD=0;implementation{$R*.DFM}(Sender:TObject);beginClose;end;(Sender:TObject);beginifidHotKey0thenExit;idHotKey:=GlobalAddAtom(‘‘‘‘EmuMouse’’’’);//给热键取得一个唯一的标识RegisterHotKey(Handle,idHotKey,0,VK_NUMPAD5);//注册热键end;(varMessage:TWMHOTKEY);varPoint:TPoint;X,Y:Word;beginGetCursorPos(Point);//取回当前坐标tryX:=StrToInt();Y:=StrToInt();exceptShowMessage(‘‘‘‘坐标输入不正确.’’’’);Exit;end;tryMouse_Event(MOUSEEVENTF_ABSOLUTE+MOUSEEVENTF_LEFTDOWN,,,0,GetMessageExtraInfo);SetCursorPos(X,Y);Mouse_Event(MOUSEEVENTF_ABSOLUTE+MOUSEEVENTF_LEFTUP,X,Y,0,GetMessageExtraInfo);exceptShowMessage(‘‘‘‘Error’’’’);end;end;(Sender:TObject);beginifidHotKey=0thenExit;UnRegisterHotKey(Handle,idHotKey);//注销热键DeleteAtom(idHotKey);//注销标识idHotKey:=0;end;(Sender:TObject);begin;end;end.--------------------------------------------------------------------------------这是dfm文件objectForm1:TForm1Left=296Top=238AutoSize=TrueBorderStyle=bsDialogBorderWidth=8Caption=‘‘‘‘模拟鼠标拖动’’’’ClientHeight=265ClientWidth=211Color=clBtnFace=GB2312_CHARSET=clWindowText=-12=‘‘‘‘新宋体’’’’=[]OldCreateOrder=FalseOnDestroy=FormDestroyPixelsPerInch=96TextHeight=12objectbtnSetHK:TButtonLeft=136Top=8Width=75Height=25Caption=‘‘‘‘设置热键(H)’‘‘‘TabOrder=0OnClick=btnSetHKClickendobjectbtnExit:TButtonLeft=136Top=72Width=75Height=25Caption=‘‘‘‘退出(X)’’’’TabOrder=2OnClick=btnExitClickendobjectGroupBox2:TGroupBoxLeft=0Top=0Width=129Height=97Caption=‘‘‘‘目的坐标’’’’TabOrder=3objectLabel3:TLabelLeft=16Top=29Width=6Height=12Caption=‘‘‘‘X’’’’endobjectLabel4:TLabelLeft=16Top=61Width=6Height=12Caption=‘‘‘‘Y’‘‘‘endobjecte邓小平os:TMaskEditLeft=32Top=24Width=73Height=20EditMask=‘‘‘‘0000;1;_’’’’MaxLength=4TabOrder=0Text=‘‘‘‘0000’’’’endobjectedYPos:TMaskEditLeft=32Top=56Width=73Height=20EditMask=‘‘‘‘0000;1;_’’’’MaxLength=4TabOrder=1Text=‘‘‘‘0000’’’’endendobjectbtnUnsetHK:TButtonLeft=136Top=40Width=75Height=25Caption=‘‘‘‘取消热键(U)’’’’TabOrder=1OnClick=btnUnsetHKClickendobjectMemo:TMemoLeft=0Top=104Width=209Height=161TabOrder=4