热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

截获键盘事件(截获F8功能健)

unitUnit1;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Qt;

type
TForm1 = class(TForm)
Button1: TButton;

procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }

end;
//function KeyHook(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;


var
Form1: TForm1;
hook: HHOOK; {定义一个钩子句柄}
implementation

{$R *.dfm}
//var

{实现键盘钩子回调函数}
function KeyHook(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT;stdcall;
begin

// ShowMessage('aaabbb '+inttostr(wParam)+' '+inttostr(lParam));
if (wParam = 119) and(lParam>0) then
begin
ShowMessage('aaa '+inttostr(wParam)+' '+inttostr(lParam)+' '+inttostr(nCode));
Beep; {每拦截到字母 A 会发声}
end;
Result := CallNextHookEx(hook, nCode, wParam, lParam);
end;



procedure TForm1.FormCreate(Sender: TObject);
begin
hook := SetWindowsHookEx(WH_KEYBOARD, @KeyHook, 0, GetCurrentThreadID);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
UnhookWindowsHookEx(hook);
end;

procedure TForm1.Button1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
//Key_Enter
end;

end.


推荐阅读
author-avatar
流浪者时空
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有