- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs;
- type
- TForm1 = class(TForm)
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- private
- procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- var
- HotKeyId: array[0..12] of Integer; //热键数组, 这里准备定义 13 个热键
- procedure TForm1.FormCreate(Sender: TObject);
- var
- i: Integer;
- begin
- //注册热键
- for i := Low(HotKeyId) to High(HotKeyId) do
- HotKeyId[i] := GlobalAddAtom(PChar(IntToStr(i))); //热键命名可随意
- RegisterHotKey(Handle,HotKeyId[0],0,VK_F2); //F2
- RegisterHotKey(Handle,HotKeyId[1],0,VK_UP); //Up
- RegisterHotKey(Handle,HotKeyId[2],0,VK_DOWN); //Down
- RegisterHotKey(Handle,HotKeyId[3],0,VK_LEFT); //Left
- RegisterHotKey(Handle,HotKeyId[4],0,VK_RIGHT); //Right
- RegisterHotKey(Handle,HotKeyId[5],0,VK_PRIOR); //PageUp
- RegisterHotKey(Handle,HotKeyId[6],0,VK_NEXT); //PageDown
- RegisterHotKey(Handle,HotKeyId[7],0,VK_OEM_PLUS); //+
- RegisterHotKey(Handle,HotKeyId[8],0,VK_OEM_MINUS); //-
- RegisterHotKey(Handle,HotKeyId[9],0,$31); //1
- RegisterHotKey(Handle,HotKeyId[10],0,$41); //a
- RegisterHotKey(Handle,HotKeyId[11],0,VK_RETURN); //Enter
- RegisterHotKey(Handle,HotKeyId[12],MOD_CONTROL,VK_RETURN); //Ctrl+Enter
- end;
- //热键
- procedure TForm1.WMHotKey(var Msg: TWMHotKey);
- begin
- if Msg.HotKey = HotKeyId[0] then ShowMessage('F2');
- if (Msg.HotKey=HotKeyId[1]) then ShowMessage('Up');
- if (Msg.HotKey=HotKeyId[2]) then ShowMessage('Down');
- if (Msg.HotKey=HotKeyId[3]) then ShowMessage('Left');
- if (Msg.HotKey=HotKeyId[4]) then ShowMessage('Right');
- if Msg.HotKey = HotKeyId[5] then ShowMessage('PageUp');
- if Msg.HotKey = HotKeyId[6] then ShowMessage('PageDown');
- if Msg.HotKey = HotKeyId[7] then ShowMessage('+');
- if Msg.HotKey = HotKeyId[8] then ShowMessage('-');
- if Msg.HotKey = HotKeyId[9] then ShowMessage('1');
- if Msg.HotKey = HotKeyId[10] then ShowMessage('a');
- if Msg.HotKey = HotKeyId[11] then ShowMessage('Enter');
- if Msg.HotKey = HotKeyId[12] then ShowMessage('Ctrl+Enter');
- end;
- procedure TForm1.FormDestroy(Sender: TObject);
- var
- i: Integer;
- begin
- //注销热键
- for i := Low(HotKeyId) to High(HotKeyId) do
- begin
- UnRegisterHotKey(handle,HotKeyId[i]);
- GlobalDeleteAtom(HotKeyId[i]);
- end;
- end;
- end.
相关推荐
Delphi实现Hotkey自定义热键功能源代码大全
Delphi作为一门强大的编程语言,它集合了快速开发与编译效率于一身,深受IT从业者的喜爱。从最初的Pascal发展而来,Delphi不仅继承了Pascal的严谨和高效,还引入了面向对象编程的特性。它采用了可视化的集成开发环境(IDE),开发者可以在其中快速设计GUI组件并编写高效的代码。Delphi广泛应用于Windows平台的应用程序开发,特别是数据库和网络通信领域。它的核心优势之一是其编译器能够生成高效的本地代码,这意味着Delphi编写的程序运行速度非常快,接近甚至优于C++等语言。
全局热键 RegisterHotKey
全局 热键 RegisterHotKey 注册
delphi设置全局快捷键
delphi设置全局快捷键
Delphi之RegisterHotKey和UnregisterHotKey
下面是根据D7的帮助手册翻译并注释过来的,不得不说按F1查看帮助手册真的很方便,就是是英文的,比中文看的久点,为了方便查询,我就顺手翻译下了。 RegisterHotKey函数用来注册全局热键到指定的句柄 下面是函数原型 BOOL RegisterHotKey( HWND hWnd, //接收热键的窗口句柄 int id, // 热键的标识id UIN...
DELPHI如何注册系统热键
用DELPHI如何注册系统热键 (2003年10月21日) 发表日期:2003-3-1 文章作者:未知 已浏览: 357 次 var i=9; fun
delphi RegisterHotKey注册快键
RegisterHotkey(self.handle,globalatom('myhostkey'),mod_control+mod_alt,VK_key12); procedure Hostkey(var msg:Tmessage);message WM_HOTKEY;egin procedure HostKey(var msg:Tmessage); begin
实现一个热键注册编辑的类
实现一个热键注册编辑的类CST(http://blog.csdn.net/mrtechno) 2005-8-19 1 文档目的... 12 热键编程基础... 12.1 API函数... 12.2 编程方法... 23 实现概述... 44 实现细节... 44.1 XML配置文档结构... 44.2 热键编辑控件 ThotKeyEdit 54.3 热键自定义窗体类TformHotKeyconf
DELPHI中使用热键
在windows中规定应用程序热键的唯一标识符取值范围在0x0000~0xBFFF之间,动态链接库的取值范围在0xC000~0XFFFF之间。 热键的辅助按键还包括Mod_Ctrl,Mod_Alt和Mod_Shift,对于windows兼容键盘,还包括windows标志键,Mod_Win。 热键设置成功后,在程序运行过程中如果有预定义的热键被按下,window
Delphi RegisterHotKey 设置系统热键
首先先贴一张热键表 Symbolic constant name Value (hexadecimal) Keyboard (or mouse) equivalent VK_LBUTTON 01 Left mouse button VK_RBUTTON 02 Right mouse button VK_CANCEL 03 Cont
delphi热键:delphi程序中定义热键的方法 --转
====================================================== 注:本文源代码点此下载 ====================================================== 疯狂代码 http://www.crazycoder.cn/ :http:/www.crazycoder.cn/delphi/article117
Delphi版的Hotkey自定义热键源代码
内容索引:Delphi源码,系统相关,Hotkey,热键 Delphi版的Hotkey自定义热键源代码,设置,录制宏、编辑描述文件,鼠标快捷方式定义,键盘快捷方式定义等,源码爱好者已经收录了不少的Delphi热键,每一个从实现的原理上都有所不同,收录这些源码更侧重于学习研究,因此学习Delphi编程的朋友有必要参阅一下源程序。注意,源码包中有多个DPR文件,要先编译生成DLL的,然后再编译热键程序。
Delphi 注册和删除热键举例.rar
Delphi 注册HotKEY热键功能,程序功能包括注册热键、删除热键,比较初级的Delphi自定义热键的例子,仅供Delphi初学者参考,编译请在Delphi7环境下进行。下面来分享两者的具体实现代码: 以下是注册热键的功能,通过修改注册表实现: procedure TForm1.FormCreate(Sender: TObject); begin hotkeyid:=GlobalAddAtom(pchar('UserDefineHotKey'))-$C000; registerhotkey(handle,hotkeyid,MOD_CONTROL or mod_Alt,$41); end; 以下是删除热键的功能,同样通过修改注册表实现: procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin unregisterhotkey(handle,hotkeyid); DeleteAtom(HotKeyID); end;
delphi编程注册热键_调出隐藏的窗体
delphi编程注册热键_调出隐藏的窗体
Delphi全局热键注册
private { Private declarations } Aatom: ATOM; procedure hotkey(var msg: TMessage); message WM_HOTKEY; procedure TForm1.FormCreate(Sender: TObject); begin if FindAtom('ZWXhotKey') = 0 th
delphi程序全局热键的自定义方法
全局热键的意思是指,当程序并不是当前窗口的时候,按下热键也可以响应。 以前做这种功能用过一种方法,是编写一个键盘钩子的DLL,过滤系统中所有的键盘消息,当然还要再写一个程序去调用它。这种方法做起来麻烦了一起,不过倒是黑客窃取键盘密码雏形。 这里介绍的方法是利用windows api直接注册热键,分三步走:1、增加一个全局Atom2、为Atom注册一个全局热键(这样相应的键盘消息就会分配给本程序...
Delphi全局热键的注册
1.在窗启动时创建ATOM;(aatom:ATOM;定义在private中) 1 if FindAtom('ZWXhotKey')=0 then 2 begin 3 aatom:=GlobalAddAtom('ZWXhotKey'); 4 end; 5 if RegisterHotKey(Handle,aatom,MOD_ALT,$41) then 6 ...
delphi热键设定的方法
问题是你要全局的.还是要系统级的,还是要局部的。 如果是全局和局部的,那么在主窗体上(或其他控件上)(form)的KeyPress等属性上监控就行了.. 如果是系统级的,那么需要API了. 简单代码: 用到3个API函数 BOOL RegisterHotKey( HWND hWnd, //响应该热键的窗口句柄 Int id, //该热键的唯一标识
Delphi 热键处理hotkey
单元引用:Uses Winapi.Messages; 函数声明: procedure HotKeyDown(var Msg: Tmessage); message WM_HOTKEY; 热键注册:窗体create中 HotKeyId := GlobalAddAtom('MyHotKey') - $C000; RegisterHotKey(Handle, HotKeyId, 0,
876




被折叠的 条评论
为什么被折叠?



