Partially found the problem. Somehow LM_CONTEXTMENU gets pushed twice to the messaging queue.
If I comment out the LM_CONTEXTMENU in TRichEditCallback.GetContextMenu, the context menu for right click doesn't work anymore, but the Menu key starts working.
function TRichEditCallback.GetContextMenu(seltype: Word; oleobj: IOleObject;
const chrg: TCharRange; var menu: HMENU): HRESULT; stdcall;
var
msg : TLMContextMenu;
begin
{
FillChar(msg, sizeof(msg), 0);
msg.Msg:=LM_CONTEXTMENU;
msg.XPos:=Mouse.CursorPos.x;
msg.YPos:=Mouse.CursorPos.y;
msg.hWnd:=fOwner.Handle;
DeliverMessage(fOwner, msg);
}
// do not give hmenu back to RichEdit, it will destory it!
menu:=0;
Result:=S_OK;
end;
Tracing through the code you see TControl.WMContextMenu is called twice for the Menu key.
So TPopupMenu.PopUp is executed twice because of this resulting in closing the just opened popup by the previous call.
I'm not sure who pushes the LM_CONTEXTMENU to the queue when the menu key is pressed... but if it's already done... TRichEditCallback.GetContextMenu shouldn't do this again.
I don't think Dmitry ( @skalogryz ) is very active with Lazarus anymore.