Why is KeyDown executed twice - only Windows lazarus / 31-LCL ---------------------------------------------------------------------- winni · 2019-12-27 22:23 Hi! I have a code that works with Linux/gtk2 with no problems. Now I tested it in Win7 and FormKeydown is executed twice. Until I stop it. Why? This 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 begin      case key of           VK_UP:       if TV[actTrack] < 255 then inc(TV[actTrack]);           VK_Down:  if TV[actTrack] > 0 then dec (TV[actTrack]);           ....        end; // case        key := 0;   // needed by windows; otherwise executed two times       ...... end;                       The Point is: key := 0;   // needed by windows; otherwise executed two times If I set after the case the key := 0 then it only is executed only once. But in  gtk2 this is not necessary. I vaguely remember that there was  a similar issue with Delphi - long, long time ago. Okay - I solved it. But perhaps there are some LCL-Freaks around who can tell me why. Winni ---------------------------------------------------------------------- lainz · 2019-12-27 23:21 I have other, create a form, and a spin edit control, run as modal window and press ESC key, on Windows it does not send the key, on linux it does. Edit: I don't remember it exactly, but try adding two onkeypress events, one or two of these are not executed on Windows. I'm using trunk of fpc and lazarus. ---------------------------------------------------------------------- jamie · 2019-12-28 00:51 I don't know how you are doing that because it does not do it here. What controls are you using ? ---------------------------------------------------------------------- ASerge · 2019-12-28 07:46 Simple test. New project. Put TLabel (Align=alTop, WordWrap=True) and add OnKeyDown to Form: 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  Label1.Caption := Label1.Caption + ', ' + IntToStr(Key);end;Triggered only once. ---------------------------------------------------------------------- jamie · 2019-12-28 16:58 must be something different on your end.. that code does not produce a double results here. I did that test with Laz 2.0.4-64, 3.0.4 Windows 10-64; also I put a static counter variable in formKeydown event, played with Key Preview etc.... single strikes only. ---------------------------------------------------------------------- Thaddy · 2019-12-28 17:01 Quote from: ASerge on December 28, 2019, 08:46:23 amSimple test. New project. Put TLabel (Align=alTop, WordWrap=True) and add OnKeyDown to Form: 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  Label1.Caption := Label1.Caption + ', ' + IntToStr(Key);end;Triggered only once. That would be a bug then.... OnKeyDown should repeatedly fire. OnKeyUp Just once. ---------------------------------------------------------------------- jamie · 2019-12-28 17:10 I just did 2.0.6 64 bit, works fine.. no doubles... but I also noticed that the Tlabel.WordWrap does not work, at all!.. So I don't know what to say ---------------------------------------------------------------------- winni · 2019-12-28 17:33 Hi! Got the "bad boy" - but this leads to another bug. I my app FormKeyDown changes the ItemIndex of a listbox on the same Form. In the Listbox  is -- grrrr -- ClickOnSelChange activated by detfault! This should not be! Second: In Windows and activated ClickOnSelChange the Listbox fires also a KeyDown event if the selection changes. That is a bug! In Linux/gtk2 this does not happen. Winni ---------------------------------------------------------------------- wp · 2019-12-28 18:17 Quote from: jamie on December 28, 2019, 06:10:50 pmbut I also noticed that the Tlabel.WordWrap does not work, at all!.. It does for me. The trick is to turn off AutoSize and to adjust the width as needed. There is a problem, though, in comparison with Delphi, that switching AutoSize back to true when the Caption is already wrapped the label jumps back to single-line mode which adjusts width and height - in Delphi, the label keeps its current width and adjusts the height only. ---------------------------------------------------------------------- wp · 2019-12-28 18:30 Quote from: winni on December 28, 2019, 06:33:20 pmClickOnSelChange activated by detfault! This should not be! It should. In dubio pro Delphi. This is not the only logical inconsistency imposed by the requirement to be compatibile with Delphi. Quote from: winni on December 28, 2019, 06:33:20 pmSecond: In Windows and activated ClickOnSelChange the Listbox fires also a KeyDown event if the selection changes. That is a bug! Post a demo project showing this. ---------------------------------------------------------------------- jamie · 2019-12-28 21:40 I don't know what to tell you but, the WORD WRAP failure was my fault, I forgot to place a space in the text, so that can be written off..  As for the list box firing a KeyDown, that is suppose to happen if the listbox has the focus.  when a list box has the focus it receives the keys are responsive so and thus selection moves.  If you put another focused type control on the form and TAB to that one, you'll see the ListBox now longer generates the event..  I just checked my old Delphi, that is the way it works there too, the key strokes come through the events and it moves the selection.  Now if you are rerferring to receiving a keystroke when Software setting the ItemIndex or Mousing it, then I would consider that a bug otherwise it looks good here.