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;
最新文章
- [转]asp.net c# 网上搜集面试题目(附答案)
- JavaScript的DOM操作-重点部分-第一部分
- MySQL之aborted connections和aborted clients
- Android:requestWindowFeature应用程序窗体显示状态操作
- 武汉科技大学ACM :1002: 零起点学算法38——求阶乘和
- s14 第5天 时间模块 随机模块 String模块 shutil模块(文件操作) 文件压缩(zipfile和tarfile)shelve模块 XML模块 ConfigParser配置文件操作模块 hashlib散列模块 Subprocess模块(调用shell) logging模块 正则表达式模块 r字符串和转译
- handler消息机制
- 勤拂拭软件 java web 开发教程(1) - 开发环境搭建
- Linux 使用 top 命令查看系统的运行情况
- Java核心技术卷一基础知识-第10章-部署应用程序和applet-读书笔记
- Linux如何统计进程的CPU利用率[转]
- 解决MAMP启动mysql服务 但是Navicat连接不上
- hibernate的native sql查询
- JDK1.7+eclipse 4.4(luna)+pydev4.4.5构建django开发环境
- SpringBoot + Spring MVC国际化使用示例
- SQL转换全角和半角函数
- 文件流的处理 C C++
- Web标准及网站的可用性、可访问性
- picks loves segment tree I
- start-stop-daemon
热门文章
- stm32 boot0 boot1的启动方式
- Grunt-jsdoc生成JS API文档
- javascript瀑布流效果
- Arduino入门笔记(4):用蜂鸣器演奏音乐并配有LED闪烁
- Arduino入门笔记(3):单LED闪烁
- 20155223 Exp8 WEB基础实践
- 洛咕3312 [SDOI2014]数表
- VS Code使用Git管理代码
- Egret(白鹭引擎)——“TypeError: Cannot read property 'asCom' of null”
- CSS快速入门-前端布局2(唯品会1)