Accessing Shortcut Key

Posted on 2005-05-16
Last Modified: 2010-05-18
How can I access the Shortcut Key of a menu item in Delphi 5.0?
Question by:fh2
    LVL 15

    Expert Comment

    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.

    Author Comment

    How can I access the event of a shortcut key? (When a user uses a shortcut key to access a menu item)
    LVL 15

    Accepted Solution

    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;


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

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

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

      Form1: TForm1;


    {$R *.dfm}

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

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

      // tell windows to continue
      Handled := True;

    LVL 15

    Expert Comment

    Take a look at the packed record structure for TWMKey to gather information as to the shortcut itself.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
    Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now