• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 599
  • Last Modified:

Accessing Shortcut Key

How can I access the Shortcut Key of a menu item in Delphi 5.0?
0
fh2
Asked:
fh2
  • 3
1 Solution
 
mikelittlewoodCommented:
Do you mean how can you assign a shortcut key to a menu item?
There is a property called ShortCut for every menu item which you can assign.

or do you mean setting the caption of a menu item to include a shortcut key?
You can set the caption to be something like &File which will display File with the F underlined just like any normal window shortcut.
Then just do the usual menu selection by pressing ALT and then all the shortcut underlined letters until you get to the item you want.
0
 
fh2Author Commented:
How can I access the event of a shortcut key? (When a user uses a shortcut key to access a menu item)
0
 
mikelittlewoodCommented:
ah ok..

The shortcuts are for the application in general rather than each menu item.
Maybe something like this. You just need to override the main forms OnShortCut event I think.

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    procedure FormCreate(Sender: TObject);

  private
    procedure MyShortcut(var Msg: TWMKey; var Handled: Boolean);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Form1.OnShortCut := MyShortcut;
end;

procedure TForm1.MyShortcut(var Msg: TWMKey; var Handled: Boolean);
begin
  // write your code here

  // tell windows to continue
  Handled := True;
end;

end.
0
 
mikelittlewoodCommented:
Take a look at the packed record structure for TWMKey to gather information as to the shortcut itself.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now