Differences between widget sets. lazarus / 31-LCL ---------------------------------------------------------------------- dbannon · 2023-01-15 05:38 This is a bit of a RFC. In my code I have, say, a TListView (that shows a list of stuff) and an TEdit that can get a term used to filter that list of stuff. If focus starts on the TListView and a user starts typing a search term, we jump to the edit and apply the filter as they type. Easy, use OnKeyDown or OnKeyPressed to change focus to the TEdit. But, I have found three different behaviors - GTK2 - exactly as I expected, press a key and its character pops up in the TEdit. User keeps typing their search term. Qt5 - while focus is switched, the key that triggers it is retained in the TListView, subsequent characters typed appear in the TEdit. Windows - same as Qt5 Similar to GTK2, the first character appears in the TEdit but its auto selected and the next character typed overwrites it. My attempts to unselect that character in the OnKeyDown event were unsuccessful. I initially reported it here, thinking it was just a Qt thing - https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/40090 Zeljan very kindly said he though jumping between controls to be a bit dodgey and I am looking at differences below the level that Lazarus can be expected to manage things. I am not personally overly concerned about it, I put some $ifdef code in my app and it works fine everywhere except on the Mac where I have quite a small user base. But it does represent different behavior, what do people think ? Simple demo (without my work around) attached. Davo ---------------------------------------------------------------------- jamie · 2023-01-15 15:08 When pressing a key, it belongs to the window/control that was active at the time, you should not be changing focus during a keydown and expect that char to traverse over to the next focused control.  In windows, there is a translateMessage call that uses the WM_KEYDOWN to generate a WM_CHAR message, this message is tagged to be sent to the window at the time when the key was down which carries the window handle.   This takes place in the message loop of the process.    So, I am not quite sure how the other widgets are handling this? Obviously not the same.   why don't you use the Keyup event to change focus and cache your character somewhere in the Keydown event. When the new control receives the focus, it can examine the cache and insert it, then empty the cache. After that, the cursor should be blinking at the next entry point. ---------------------------------------------------------------------- dbannon · 2023-01-15 22:48 Quote from: jamie on January 15, 2023, 04:08:29 pmWhen pressing a key, it belongs to the window/control that was active at the time, you should not be changing focus during a keydown and expect that char to traverse over to the next focused control. I sort of considered that the KeyDown event is an event in its own right, it gets called before any other processing (or use) of the key happens. But seems I simplified the problem.... Quote from: jamie on January 15, 2023, 04:08:29 pm  why don't you use the Keyup event to change focus and cache your character somewhere in the Keydown event. When the new control receives the focus, it can examine the cache and insert it, then empty the cache. After that, the cursor should be blinking at the next entry point. In fact, my working code is simpler than that, on Win32 and Qt5 in OnKeyPress, I just poke that character into the new ctrl (shown here without any of the sanity checks) - 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 TSearchForm.ListViewNotesKeyPress(Sender: TObject; var Key: char);begin    editSearch.setfocus;     EditSearch.Caption  := EditSearch.Caption+char(Key);.... But that does not work on MacOS, as mentioned. I considered poking the char into a regional var (and then clearing that var) and looking at that var every time the EditSearch gets focus, that should work but is somewhat more complicated, maybe fragile and will need more work than I have time for right now. Maybe the next release now that I am starting to realise that GTK2's "it all just works" model is the anomaly. Davo