- - * - WhiteUnicorn - * - -




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >


Frequently Asked Questions

How can I detect if a non-menu key has been pressed?

Question:

How can I detect if a non-menu key has been pressed while a menu is displayed?

Answer:

Create a message handler for the WM_MENUCHAR character message.

Example:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
    Dialogs, Menus;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    One1: TMenuItem;
    Two1: TMenuItem;
    THree1: TMenuItem;
  private
    { Private declarations }
    procedure WmMenuChar(var m : TMessage); message WM_MENUCHAR;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.WmMenuChar(var m : TMessage);
begin
  Form1.Caption := 'Non standard menu key pressed';
  m.Result := 1;
end;

end.



* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >



- - * - Anastasija aka WhiteUnicorn - * - - LJLiveJournal
PFPhotoFile