Some controls lock keyboard inside. lazarus / 31-LCL ---------------------------------------------------------------------- vrull · 2012-10-09 07:05 I noticed that some controls (TStringGrid, TMemo) lock keyboard. For example, if a form has TActionList with shortcuts assigned to some actions, the shortcuts work until the above-mentioned control takes focus. When focus moves away from say TStringGrid, shortcuts start working again. Is there any way to maintain higher priority for actions over internal processing in the controls? Otherwise this makes ActionLists unreliable and un-usable. ---------------------------------------------------------------------- Bart · 2012-10-09 08:45 Can you attach a minimal test-case sample project (sources only)? Bart ---------------------------------------------------------------------- vrull · 2012-10-10 08:42 I apologize for misleading. The only actions blocked by TStringGrid are those with Enter key, like fired by Ctrl+Enter, Alt+Enter combinations, when the grid is in editor mode. This does not happen in Delphi, this is why I made such a broad statement. I used to allocate Enter for navigation through edit controls on the form and Ctrl+Enter as a shortcut for "Save" action from any position. This approach does not work with Lazarus. So the question is still open - can I force processing shortcuts in ActionList first, before they got into StringGrid? I don't want to add extra code into OnKeyUp event, because action shortcuts are configurable, users can set them according to their taste, so any hard-coded key code checks are not the solution. The test project is attached, it has four actions with shortcuts: F5, Ctrl+T, Ctrl+Enter and Alt+Enter ---------------------------------------------------------------------- User137 · 2012-10-10 10:26 Quote from: vrull on October 10, 2012, 10:42:12 amI don't want to add extra code into OnKeyUp event, because action shortcuts are configurable, users can set them according to their taste, so any hard-coded key code checks are not the solution.Who says you have to hard-code key codes if you use onKeyUp    I have never in my life used TActionList, thanks for letting me know such exists. But then, i make mostly games anyway. ---------------------------------------------------------------------- Blaazen · 2012-10-10 10:32 QuoteSo the question is still open - can I force processing shortcuts in ActionList first, before they got into StringGrid? I don't want to add extra code into OnKeyUp event, because action shortcuts are configurable, users can set them according to their taste, so any hard-coded key code checks are not the solution. These key combinations are already hardcoded (in grids.pas). BTW, you can also try to put TComboBox and create new action with assigned Alt+ArrowDown, it will not work either because this combination opens list of combo. IMO you have 3 chances: 1) Set KeyPreview of the Form to True and manage such combinations. 2) Use your own grid editors with modified KeyDown methods. 3) of course, don't use such combination at all. Here is link to custom cell editors: http://wiki.lazarus.freepascal.or g/Grids_Reference_Page#Example:_How_to_set_a_custom_cell_editor ---------------------------------------------------------------------- vrull · 2012-10-11 08:24 To Blaazen. Thank you for your reply. TCustomGrid processes VK_RETURN in OnKeyDown event and sets then Key := 0 regardless of the key modifiers, although it uses only plain press and Shift+Enter combination. As a quick check I added a single "if" clause in front and this immediately resolved the issue. (file dbgrid.pas)Code: [Select]TCustomGrid.KeyDown(Sender ...)... ... VK_RETUN: if Shift * [ssAlt, ssCtrl] = [] then // this is added by me begin ... I added same check for onKeyDown event in embedded editors in the same file, rebuilt Lazarus and got what I wanted - no changes in TStringGrid behaviour, but Ctrl+Enter and Alt+Enter shortcuts can be used for triggering Actions. (tested on Windows so far) This hack is not good for Open Source projects, because I am not going to supply modified dbgrid.pas along with my source code, but works fine as a temporary solution. ---------------------------------------------------------------------- Bart · 2012-10-11 09:45 I think you should open an issue in the bugtraker for this. Bart ---------------------------------------------------------------------- User137 · 2012-10-11 11:53 Would more general code for it be this: Code: [Select]VK_RETURN: if Shift = [] then There are many shift states, including ssShift and mousebuttons. All of them should be off for default behavior, right? Or remove the "Key := 0". ---------------------------------------------------------------------- vrull · 2012-10-12 08:01 Quote from: User137 on October 11, 2012, 01:53:35 pmWould more general code for it be this: Code: [Select]VK_RETURN: if Shift = [] then There are many shift states, including ssShift and mousebuttons. All of them should be off for default behavior, right? Or remove the "Key := 0". This is too general. Shift+Enter is used for navigation backward through the grid, so I should not disable this. Setting Key := 0 may cause unforeseen subsequences, single key press can be processed more than once, this is rather un-safe approach. ---------------------------------------------------------------------- User137 · 2012-10-12 08:17 Quote from: vrull on October 12, 2012, 10:01:14 amThis is too general. Shift+Enter is used for navigation backward through the grid, so I should not disable this. Setting Key := 0 may cause unforeseen subsequences, single key press can be processed more than once, this is rather un-safe approach.I'm not currently on home computer to access Lazarus code, but i don't know if any of that is related. I was trying to tackle problem where TCustomGrid stops input to all VK_RETURN cases, and doesn't pass anything onwards. I don't know what happens in that code, but i assume something like: Code: [Select]case VK_RETURN: // if Shift = [] then // This whole "if" was added by us, propably originally doesn't exist   begin     CloseEditor;     key:=0;   end; ... if editor.Visible and (key>0) then editor.text:=editor.text+chr(key);With the "if", this would cause ctrl+enter to not close the field-editor, but let other components get it. It's just speculation... It would be stupid if the code was actually like that, but it's only reason i can imagine to justify adding key:=0; Maybe like that related to typing. Trying to prevent VK_RETURN key from being added to the text itself. Component should never halt user input, the above code is very poor design.