how to detect what has fired a popupmenu when shortcut key used? lazarus / 31-LCL ---------------------------------------------------------------------- Josh · 2017-06-05 09:17 Hi I have been using the same popup menu on various grids, I can use the Fired_From_Component := PopupMenu1.PopupComponent.Name; in the onpopup event, but this is not fired on a shortcut key. Using the popupcomponent.name within the menuitem event; when using shortcut keys contains the value of the last popup menu activated by mouse. is there a similar event available for when shortcut keys are used to invoke a menuitem. ---------------------------------------------------------------------- sky_khan · 2017-06-05 09:41 I'm not sure that I understand the problem but I guess you can probably use form's ActiveControl property. It gives you which control has focus at the moment. This way it doesnt matter if popup activated by keyboard or mouse. ---------------------------------------------------------------------- Thaddy · 2017-06-05 09:56 Quote from: josh on June 05, 2017, 11:17:03 amHi I have been using the same popup menu on various grids, I can use the Fired_From_Component := PopupMenu1.PopupComponent.Name; in the onpopup event, but this is not fired on a shortcut key. Using the popupcomponent.name within the menuitem event; when using shortcut keys contains the value of the last popup menu activated by mouse. is there a similar event available for when shortcut keys are used to invoke a menuitem. OnKeyDown, OnKeyUp for the parent form give you both key and shiftstate, etc. Other option: OnMessage hook for TApplication. TShortcut itself is just a word, not a class, alas. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState  );begin  Caption :=Format('key %d, ShiftState %d',[Key,integer(Shift)]);  inherited;end;You will see that the item on the menu still works and receives focus. ---------------------------------------------------------------------- Josh · 2017-06-05 11:16 Hi I should have added, so I have also added in a simple example project to show the issue ( created with latest SVN). i use the onpopuop event to enable disable hide controls that are non appropriate depending on what has been set in other parts of the program, as the onpopup is not called when a shortcut is used, it is possible to activate shortcuts that would not be available if you were to use the mouse to activate the menu. In the example project, if you right click in memo1, the option Explode is available, and triggers from menu or shortcut, if you move into memo 2 and press ctrl-e the it is still triggered, if you bring up menu in memo 2, then the ctrl-e is not enabled and also will not trigger if pressed within memo2. I suppose a quick fix would be to calll a derivative of the onpopup event; when ever I enter any component that has a popupmenu so as to set available options and also fire a similar routine when ever any text is manipulated or highlighted so as to display/set the relevant options on the menu; which then makes the shortcuts fire correctly. Josh ---------------------------------------------------------------------- sky_khan · 2017-06-05 16:25 I believe I already pointed you to right direction but you did not listen. Anyways, check this if it is what you want. ---------------------------------------------------------------------- Josh · 2017-06-05 18:12 Hi SkyKhan, Thanks for your reply. I opened your zip and it contains lfm and pas file, no project info? How can I open this to test? Thanks ---------------------------------------------------------------------- sky_khan · 2017-06-05 18:20 I just modified your example's main form and put them in a zip. Replace yours with mine (extract my zip into your example project folder) . Backup your example project folder first if you wish. ---------------------------------------------------------------------- Thaddy · 2017-06-05 18:38 Quote from: SkyKhan on June 05, 2017, 08:20:49 pmI just modified your example's main form and put them in a zip. Replace yours with mine (extract my zip into your example project folder) . Backup your example project folder first if you wish. But it is a... generic solution.  Half of it requires.... Oh well. ---------------------------------------------------------------------- mangakissa · 2017-06-06 07:11 Quote from: josh on June 05, 2017, 11:17:03 amHi I have been using the same popup menu on various grids, I can use the Fired_From_Component := PopupMenu1.PopupComponent.Name; in the onpopup event, but this is not fired on a shortcut key. Using the popupcomponent.name within the menuitem event; when using shortcut keys contains the value of the last popup menu activated by mouse. is there a similar event available for when shortcut keys are used to invoke a menuitem. Use Tactionlist. ---------------------------------------------------------------------- Josh · 2017-06-06 10:18 Hi SkyKhan, Your solution does indeed work. As my onpopup event in my application is rather bloated, ie popup and shortcuts are created dynamically each time a onpopup is called up, a menu could be 4 items or over 20. The issue I had only occured when I started adding in shortcut keys, and became aware that the popupmenu shortcut keys can stay active when in a control that should not be active. So was after a way force a onpopup when shortcuts are used. I have played around with grabbing the ctrl key in form events and then firing the onpopup event, this also seems to be working, without to much change of applicatioin and no additional components or controls. ie, this is rough and needs fine tuning etc. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  var last_fired_from:string=''; // this is used to stop auto-repeat of ctrl firing the onpopup routine continuously procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState  );begin  if Shift = [ssCtrl] then  begin    // now check if active control has popupmenu    try      if last_fired_from<>activecontrol.name then      begin        last_fired_from:=activecontrol.name;        if assigned(activecontrol.PopupMenu) then        begin          if (findcomponent(activecontrol.PopupMenu.Name) as tpopupmenu).OnPopup<>nil then          begin            (findcomponent(activecontrol.PopupMenu.Name) as tpopupmenu).PopupComponent:=activecontrol;  // sets popupcpomponent to activecontrol.            (findcomponent(activecontrol.PopupMenu.Name) as tpopupmenu).OnPopup(activecontrol); // fire the onpoup event        end;        end;      end;    finally    end;  end  else  begin   // ctrl not pressed so reset     last_fired_from:='';  end;end;  procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);begin  last_fired_from:='';  / reset this so ctrl key can still fire the onpopup if ctrl released and pressed again in same controlend; ---------------------------------------------------------------------- sky_khan · 2017-06-06 10:41 Nice to know you now have a solution . I knew you need to use activecontrol after all