unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;type TForm1 = class(TForm) private { Private declarations } public { Public declarations } procedure gettab(var msg:Tmessage);message WM_KEYUP; end; var Form1: TForm1;implementation{$R *.dfm} procedure TForm1.gettab(var msg:Tmessage); begin if integer(msg.WParam) = VK_TAB then showmessage('tab get'); end; end. 搞定!
不好意思刚才没看清,好象确实如斑竹所说的一样, 下面的肯定行 function HookProc(iCode: integer; wParam: wParam; lParam: lParam): LResult; stdcall; var s:string; begin if (PEventMsg(lparam)^.message = WM_KEYDOWN) then begin if peventMsg(lparam)^.paramL =3849 then //tab键的扫描码 begin //showmessage('get')//在xp下,总是不断弹出,最后异常,可能是因为弹出新窗体,//局部钩子就无效了吧。不过肯定是捕获到了tab end; end ;end; procedure TForm1.FormCreate(Sender: TObject); begin SetWindowsHookEx(WH_JOURNALRECORD, HookProc, HInstance, 0); end;
if key = vk_tab then begin . . . end;
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = 9 then ShowMessage('TAB!'); end;
这还需要测试吗?
只要设置keypreview属性为true,然后你就可以在onKeyPress事件检查Key值了
Shift: TShiftState);
begin
if Key = $9 then
ShowMessage('TAB key pressed!');
end;这样很好啊。
只要设置keypreview属性为true,然后你就可以在onKeyPress事件检查Key值了”
请你先试一下再说吧,不信你写段代码试试
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations } procedure gettab(var msg:Tmessage);message WM_KEYUP;
end;
var
Form1: TForm1;implementation{$R *.dfm}
procedure TForm1.gettab(var msg:Tmessage);
begin
if integer(msg.WParam) = VK_TAB then showmessage('tab get');
end;
end.
搞定!
下面的肯定行
function HookProc(iCode: integer; wParam: wParam; lParam: lParam): LResult; stdcall;
var
s:string;
begin
if (PEventMsg(lparam)^.message = WM_KEYDOWN) then
begin if peventMsg(lparam)^.paramL =3849 then //tab键的扫描码
begin
//showmessage('get')//在xp下,总是不断弹出,最后异常,可能是因为弹出新窗体,//局部钩子就无效了吧。不过肯定是捕获到了tab
end;
end ;end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowsHookEx(WH_JOURNALRECORD, HookProc, HInstance, 0);
end;
begin
.
.
.
end;
Shift: TShiftState);
begin
if Key = 9 then
ShowMessage('TAB!');
end;