Jump to content

keybd_event how trigger event ?


Mauri

Recommended Posts

In my Delphi application I have a Memo component custom inherited from TCustomMemo class that has an implementation in onKeyPress method so that when the user clicks twice in a row the ENTER key the focus goes to the next component.

  TIDMemo = class(TCustomMemo)
  private
    ...
    fTabEnter: Boolean;
    fKeyAnt: Char;
  protected
    ...
    procedure KeyPress(var Key: Char); override;
  public
    ...
  published
    ... 
  end;


procedure TIDMemo.KeyPress(var Key: Char);
begin
  if ((key = #13) and (fKeyAnt = #13) and fTabEnter) or
    ((key = #13) and (MaxLength > 0) and (length(Lines.Text) > MaxLength - 2) and fTabEnter) then
    if (Lines.Count > 0) then
      if (trim(Lines.Strings[Lines.Count - 1]) = '') or (length(Lines.Text) > MaxLength - 2) then
        begin
          key:= #0;
          inherited;
          if (trim(Lines.Strings[Lines.Count - 1]) = '') then
            key:= #8;
          keybd_event(9,0,0,0); // Triggers TAB Key
          exit;
        end;
  fKeyAnt:= Key;
  inherited;
end;

Link to comment
Share on other sites

Hi,

 

If I understand correctly you, can you analyze and modify this code?!:

  ...
  public
    { Public declarations }
    fTabEnter: Boolean;
    fKeyAnt: Char;
  end;  
  ...
procedure TMainForm.UniMemo1KeyPress(Sender: TObject; var Key: Char);
begin
  fTabEnter := True;
  if ((key = #13) and (fKeyAnt = #13) and fTabEnter) then
  begin
    fKeyAnt := #0;
    SelectNext(TUniMemo(Sender));
  end;
  fKeyAnt := Key;
end;

Best regards.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...