zoukankan      html  css  js  c++  java
  • Delphi中如何实现模拟组合按键,如发送Ctrl+F的按键

    利用 keybd_event函数可实现,如下面的代码用以实现在一个公共菜单中模拟Ctrl_F按钮以调用DBGridEH的查找对话框功能:
    这是在一个ActionList中的某一Action的OnExecute事件代码。

    procedure TDM.act_LocateExecute(Sender: TObject); 
    var
      myPopupMenu:TPopupMenu; 
      MyDBGridEH:TDBGridEh; 
    begin
      //ShowMessage(TMenuItem(TAction(Sender).ActionComponent).GetParentComponent.Name); 
      if (TAction(Sender).ActionComponent).GetParentComponent is TPopupMenu then
        myPopupMenu := (TAction(Sender).ActionComponent).GetParentComponent as TPopupMenu 
      else
        Exit; 
     
      //ShowMessage(MyPopupMenu.PopupComponent.Name); 
      if (MyPopupMenu.PopupComponent is TDBGridEh) then
      begin
        MyDBGridEH := TDBGridEh(MyPopupMenu.PopupComponent); 
        MyDBGridEH.SetFocus; 
        keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), 0, 0);       //按下Ctrl键 
        keybd_event(ord('F'), MapVirtualKey(ord('F'), 0), 0, 0);                    //按下F键 
        keybd_event(ord('F'), MapVirtualKey(ord('F'), 0), KEYEVENTF_KEYUP, 0);    //放开F键 
        keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), KEYEVENTF_KEYUP, 0); //放开Ctrl键 
      end; 
    end;

  • 相关阅读:
    函数封装总结
    03.深入javascript
    02.JavaScript基础下
    html5权威指南:客户端分区响应图
    html5权威指南:定制input元素
    html5权威指南:表单元素
    html5权威指南:表格元素
    html5权威指南:组织内容、文档分节
    css布局理解
    html5权威指南:标记文字
  • 原文地址:https://www.cnblogs.com/jijm123/p/8088159.html
Copyright © 2011-2022 走看看