国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

利用熱鍵控制鼠標移動的一個程序

2019-11-18 18:47:02
字體:
來源:轉載
供稿:網(wǎng)友

本程序可以使用熱鍵來將鼠標移動到某一個指定的坐標。是一個定義熱鍵的示例程序。

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

 

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'); //給熱鍵取得一個唯一的標識
  RegisterHotKey(Handle, 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
    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); //注銷熱鍵
  DeleteAtom(idHotKey); //注銷標識
  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 = '模擬鼠標拖動'
  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 = '設置熱鍵(&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 = '目的坐標'
    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


上一篇:VCL中消息處理初探

下一篇:軟件開發(fā)的管理和控制

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
學習交流
熱門圖片

新聞熱點

疑難解答

圖片精選

網(wǎng)友關注

主站蜘蛛池模板: 昌宁县| 鄂伦春自治旗| 黎平县| 神木县| 南安市| 庆城县| 慈溪市| 汝城县| 柳林县| 黄平县| 满城县| 丹东市| 方正县| 铜陵市| 界首市| 乌拉特后旗| 南平市| 闵行区| 化州市| 杭锦后旗| 芷江| 綦江县| 辽宁省| 南陵县| 兴仁县| 宁城县| 锡林浩特市| 阳新县| 西昌市| 额敏县| 永宁县| 内黄县| 德惠市| 通州市| 河北省| 丁青县| 呼玛县| 获嘉县| 云浮市| 富宁县| 乐都县|