Q:

Delphi Menuitem open by code

I have the following TMainMenu structure (just an example):
File | Edit | Setting
 New
   Item1
   Item2
     Item2.2
   Item3
Open
Close

The menu is closed so when not used it looks:
File | Edit | Setting

What I need is that if the user presses Ctrl+N, the main menu would open (without click) the New like this:
File | Edit | Setting
 New  <---- THIS WOULD BE HIGHLIGHTED 
   Item1
   Item2
     Item2.2
   Item3
Open
Close

How can I do it?
Thank you

A:

The platform UX guidelines dictate that CTRL shortcuts should be used to invoke actions. They should not be used to navigate menus.
However, menus already have deep and rich support for keyboard navigation. Perhaps your program has not enabled it, or perhaps your user has not learnt how to use it. The keyboard navigation for menus is invoked using either the F10 key, or much more commonly the ALT key. 
So, assuming that you have either defined accelerator keys for your menu items, or set AutoHotkeys to True on your TMainMenu object, your program will already support rich menu navigation.
To open your File menu up you do ALT + F. To open the sub-menu under New you do ALT + F, N. To navigate within that sub-menu, use the arrow keys.
This navigation is supported in practically every application on the system so that users have to learn one way to use a program, and have that learning be applicable everywhere.
If you are absolutely desperate that you must be able to open menus in response to shortcuts, then you could fake input:
procedure TMyForm.MyActionExecute(Sender: TObject);
var
  Input: TInput;
  Inputs: TList<TInput>;
begin
  Inputs := TList<TInput>.Create;
  try
    Input := Default(TInput);
    Input.Itype := INPUT_KEYBOARD;

    Input.ki.wVk := VK_F10;
    Input.ki.dwFlags := KEYEVENTF_KEYDOWN;
    Inputs.Add(Input);

    Input.ki.wVk := VK_F10;
    Input.ki.dwFlags := KEYEVENTF_KEYUP;
    Inputs.Add(Input);

    Input.ki.wVk := ord('F');
    Input.ki.dwFlags := KEYEVENTF_KEYDOWN;
    Inputs.Add(Input);

    Input.ki.wVk := ord('F');
    Input.ki.dwFlags := KEYEVENTF_KEYUP;
    Inputs.Add(Input);

    Input.ki.wVk := ord('N');
    Input.ki.dwFlags := KEYEVENTF_KEYDOWN;
    Inputs.Add(Input);

    Input.ki.wVk := ord('N');
    Input.ki.dwFlags := KEYEVENTF_KEYUP;
    Inputs.Add(Input);

    SendInput(Inputs.Count, Inputs.List[0], SizeOf(TInput));
  finally
    Inputs.Free;
  end;
end;

I'm showing you this because it is an answer to the question that you asked. I would not honestly recommend using this idea.

