91精品人妻互换日韩精品久久影视|又粗又大的网站激情文学制服91|亚州A∨无码片中文字慕鲁丝片区|jizz中国无码91麻豆精品福利|午夜成人AA婷婷五月天精品|素人AV在线国产高清不卡片|尤物精品视频影院91日韩|亚洲精品18国产精品闷骚

您當(dāng)前位置:首頁(yè) > 新聞?lì)l道 > 技術(shù)動(dòng)態(tài) > 正文
利用熱鍵控制鼠標(biāo)移動(dòng)的一個(gè)程序芻議
-

本程序可以使用熱鍵來(lái)將鼠標(biāo)移動(dòng)到某一個(gè)指定的坐標(biāo)。是一個(gè)定義熱鍵的示例程序。

本程序的熱鍵為小鍵盤(pán)的5,在編輯框內(nèi)可以指定坐標(biāo)。

 

unit MainUnit;

interface

uses
  Windows, Messages, SysUtils, classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Mask;

type
  TForm1 = class(TForm)
    btnSetHK: TButton;
    btnExit: TButton;
    GroupBox2: TGroupBox;
    Label3: TLabel;
    Label4: TLabel;
    btnUnsetHK: TButton;
    edYPos: TMaskEdit;
    edXPos: TMaskEdit;
    Memo: TMemo;
    procedure btnExitClick(Sender: TObject);
    procedure btnSetHKClick(Sender: TObject);
    procedure btnUnsetHKClick(Sender: TObject);
    procedure OnHotKey(var Message: TWMHOTKEY); message WM_HOTKEY;
    procedure FormDestroy(Sender: TObject);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

const
  idHotKey : WORD = 0;

implementation

{$R *.DFM}

procedure TForm1.btnExitClick(Sender: TObject);
begin
 
  Close;
end;

procedure TForm1.btnSetHKClick(Sender: TObject);
begin
  if idHotKey<>0 then Exit;
  idHotKey := GlobalAddAtom('EmuMouse'); //給熱鍵取得一個(gè)唯一的標(biāo)識(shí)
  RegisterHotKey(Handle, idHotKey, 0, VK_NUMPAD5); //注冊(cè)熱鍵
end;

procedure TForm1.OnHotKey(var Message: TWMHOTKEY);
var
  Point: TPoint;
  X, Y: Word;
begin
  GetCursorPos(Point); //取回當(dāng)前坐標(biāo)

  try
    X := StrToInt(edXPos.Text);
    Y := StrToInt(edYPos.Text);
  except
    ShowMessage('坐標(biāo)輸入不正確.');
    Exit;
  end;

  try
    Mouse_Event(MOUSEEVENTF_ABSOLUTE+MOUSEEVENTF_LEFTDOWN, Point.X, Point.Y, 0, GetMessageExtraInfo);

    SetCursorPos(X, Y);

    Mouse_Event(MOUSEEVENTF_ABSOLUTE+MOUSEEVENTF_LEFTUP, X, Y, 0, GetMessageExtraInfo);

  except
    ShowMessage('Error');

  end;
end;

procedure TForm1.btnUnsetHKClick(Sender: TObject);
begin
  if idHotKey = 0 then Exit;
  UnRegisterHotKey(Handle, idHotKey); //注銷(xiāo)熱鍵
  DeleteAtom(idHotKey); //注銷(xiāo)標(biāo)識(shí)
  idHotKey := 0;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  btnUnsetHK.Click;
end;

end.

 


--------------------------------------------------------------------------------


這是dfm文件

object Form1: TForm1
  Left = 296
  Top = 238
  AutoSize = True
  BorderStyle = bsDialog
  BorderWidth = 8
  Caption = '模擬鼠標(biāo)拖動(dòng)'
  ClientHeight = 265
  ClientWidth = 211
  Color = clBtnFace
  Font.Charset = GB2312_CHARSET
  Font.Color = clWindowText
  Font.Height = -12
  Font.Name = '新宋體'
  Font.Style = []
  OldCreateOrder = False
  OnDestroy = FormDestroy
  PixelsPerInch = 96
  TextHeight = 12
  object btnSetHK: TButton
    Left = 136
    Top = 8
    Width = 75
    Height = 25
    Caption = '設(shè)置熱鍵(&H)'
    TabOrder = 0
    OnClick = btnSetHKClick
  end
  object btnExit: TButton
    Left = 136
    Top = 72
    Width = 75
    Height = 25
    Caption = '退出(&X)'
    TabOrder = 2
    OnClick = btnExitClick
  end
  object GroupBox2: TGroupBox
    Left = 0
    Top = 0
    Width = 129
    Height = 97
    Caption = '目的坐標(biāo)'
    TabOrder = 3
    object Label3: TLabel
      Left = 16
      Top = 29
      Width = 6
      Height = 12
      Caption = 'X'
    end
    object Label4: TLabel
      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
    OnClick = btnUnsetHKClick
  end
  object Memo: TMemo
    Left = 0
    Top = 104
    Width = 209
    Height = 161
    TabOrder = 4
  end
end

關(guān)鍵字:通訊
About Us - 關(guān)于我們 - 服務(wù)列表 - 付費(fèi)指導(dǎo) - 媒體合作 - 廣告服務(wù) - 版權(quán)聲明 - 聯(lián)系我們 - 網(wǎng)站地圖 - 常見(jiàn)問(wèn)題 - 友情鏈接
Copyright©2014安裝信息網(wǎng) m.78375555.com. All rights reserved.
服務(wù)熱線:4000-293-296 聯(lián)系電話:0371-61311617 傳真:0371-55611201 QQ: 郵箱:zgazxxw@126.com 豫ICP備18030500號(hào)-4
未經(jīng)過(guò)本站允許,請(qǐng)勿將本站內(nèi)容傳播或復(fù)制
安全聯(lián)盟認(rèn)證