zoukankan      html  css  js  c++  java
  • Delphi中由控件坐标模拟点击控件

    ----------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键。

  • 相关阅读:
    2013百度轻应用巡讲沙龙上海站
    xcode自动打ipa包脚本 资料
    Xcode 自动对齐 插件
    Lable中添加链接文字。。。各种操作 都能满足。简单易用【NIAttributedLabel】
    XMPP 安装ejabberd 搭建服务器环境
    git 终端命令行工具(忽略大小写,很好用)
    IOS团队开发之——CocoaPods 第三方库管理工具
    XCode 调试方法 (很全 很有用)
    模块化设计-iOS团队协作开发 v1.0
    淘宝技术部(ios 优化方案)
  • 原文地址:https://www.cnblogs.com/dmqhjp/p/14372439.html
Copyright © 2011-2022 走看看