Jak*_*ako 12 delphi keyboard delphi-7
我需要拦截TEdits上的TAB键盘笔划并以编程方式抑制它们.在某些情况下,我不希望焦点转移到下一个控件.
我尝试在TEdit级别和TForm上使用KeyPreview = true处理KeyPress,KeyDown.我偷看了以下建议:
但它没有用.事件被触发,比方说,输入键但不是TAB键.
我正在使用Delphi 7.感谢您的帮助.
TLa*_*ama 17
如果要拦截TAB键行为,则应捕获该CM_DIALOGKEY消息.在此示例中,如果将YouWantToInterceptTab布尔值设置为True,TAB则将使用该键:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
private
YouWantToInterceptTab: Boolean;
procedure CMDialogKey(var AMessage: TCMDialogKey); message CM_DIALOGKEY;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.CMDialogKey(var AMessage: TCMDialogKey);
begin
if AMessage.CharCode = VK_TAB then
begin
ShowMessage('TAB key has been pressed in ' + ActiveControl.Name);
if YouWantToInterceptTab then
begin
ShowMessage('TAB key will be eaten');
AMessage.Result := 1;
end
else
inherited;
end
else
inherited;
end;
end.
Run Code Online (Sandbox Code Playgroud)