procedure TFrmMain.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
showmessage('hello');
end;鼠标滚轮事件中showmessage('hello')有响应,键盘按下事件中不能为什么?很奇怪。
解决方案 »
- 求助!!关于字符排列!
- 求公司管理系统
- 大家知道 DevExpress ExpressBar Suite. v5.4 要怎么安装吗?!
- fast report 报表子报表的问题
- 高分求助:如何知道一DOS程序的句柄并将其终止?
- 理解Dephil中的System限定符?
- 自动添加编号问题
- SkinEngine如何使用?比如加载一个不规则的窗体。
- 请问我在制作ActiveX控件时,怎样触发自己添加的事件哪?
- 怎么让复选框起到作用? 下面是我自己写的,我想让我自己定义的 fengzhu 在我点了复选框后起到执行的作用·。在线等急!!
- 逐行遍历一个treelist树的方法
- 如何向其他程序中的toolbar中ToolButton发送点击按钮???
f KeyPreview is true, keyboard events occur on the form before they occur on the active control.
If KeyPreview is false, keyboard events occur only on the active control.
我可以提供给你一个热键动态链接DLL http://www.susuo.com/bbs.official/UpFile/UpAttachment/2006-11/2006111311295.rar具体用法实例:
unit TestHookKey_Unit;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;const
WM_HOOKKEY= WM_USER + $1000;
HookDLL = 'Key.dll';
type
THookProcedure=procedure; stdcall;
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
FileMapHandle : THandle;
PMem : ^Integer;
HandleDLL : THandle;
HookOn,
HookOff : THookProcedure;
procedure HookKey(var message: TMessage); message WM_HOOKKEY; public
{ Public declarations }
end;
var
Form1: TForm1;implementation{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
HandleDLL:=LoadLibrary( PChar(ExtractFilePath(Application.Exename)+
HookDll) );
if HandleDLL = 0 then raise Exception.Create('未发现键盘钩子DLL');
@HookOn :=GetProcAddress(HandleDLL, 'HookOn');
@HookOff:=GetProcAddress(HandleDLL, 'HookOff');
IF not assigned(HookOn) or
not assigned(HookOff) then
raise Exception.Create('在给定的 DLL中'+#13+
'未发现所需的函数'); FileMapHandle:=CreateFileMapping( $FFFFFFFF,
nil,
PAGE_READWRITE,
0,
SizeOf(Integer),
'TestHook'); if FileMapHandle=0 then
raise Exception.Create( '创建内存映射文件时出错');
PMem:=MapViewOfFile(FileMapHandle,FILE_MAP_WRITE,0,0,0);
PMem^:=Handle;
HookOn;
end;
procedure TForm1.HookKey(var message: TMessage);
var
KeyName : array[0..100] of char;
Accion : string;
begin
GetKeyNameText(Message.LParam,@KeyName,100);
if ((Message.lParam shr 31) and 1)=1
then Accion:='Key Up'
else
if ((Message.lParam shr 30) and 1)=1
then Accion:='ReKeyDown'
else Accion:='KeyDown';
if String(KeyName)=‘A’ then
//具体用法你来定!
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
if Assigned(HookOff) then
HookOff;
if HandleDLL<>0 then
FreeLibrary(HandleDLL);
if FileMapHandle<>0 then
begin
UnmapViewOfFile(PMem);
CloseHandle(FileMapHandle);
end;
end;end.