ActiveControl lazarus / 31-LCL ---------------------------------------------------------------------- Weitentaaal · 2021-07-21 07:31 Hello Just a Short Question: I have i field in wich i can move lets say an object with arrow Key's. But if i Press key Down then i noticed that my ComboBox still got the Focus and changed the Itemindex there to. How can i unfocus all Controls before doing some KeyDown Events ? Thanks in advice ---------------------------------------------------------------------- Weitentaaal · 2021-07-21 14:17 could not follow you  can u explain this a bit better ? "Use the key stroke events of the form instead and you test who has the focus at that time, too." ---------------------------------------------------------------------- lucamar · 2021-07-21 15:59 Quote from: Weitentaaal on July 21, 2021, 04:17:15 pm"Use the key stroke events of the form instead and you test who has the focus at that time, too."Set the form's KeyPreview to True and use its OnKeyDown event. This will then be triggered before that of any other control. Inside the handler for the later you can use: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 if SomeControl.Focused then ....to know if some control has the focus and act (or not) accordingly, if you need to. That's basically it ---------------------------------------------------------------------- Weitentaaal · 2021-07-22 13:04 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 TStartUp.FormKeyDown(Sender: TObject; var Key: Word;  Shift: TShiftState);begin  case Key of     VK_UP: if (ssShift in Shift) then MoveWholeUnit(dirBackward) else MoveWholeUnit(dirUp);     VK_DOWN: if (ssShift in Shift) then MoveWholeUnit(dirForward) else MoveWholeUnit(dirDown);     VK_LEFT: MoveWholeUnit(dirLeft);     VK_RIGHT: MoveWholeUnit(dirRight);  end;end;  Wont work with this code ... any idea ? ---------------------------------------------------------------------- lucamar · 2021-07-22 18:05 "Won't work" is not quite a good description of the problem, don't you think? Rather tell us what it does that it shouldn't or doesn't that should. Just in case, check (again?) whether you have both: Set the form's KeyPreview to True; andThe OnKeyDown property is correctly set to point to the handler Also, set a breakpont at the start (or add a ShowMessage() or set some label's caption or a status bar panel's Text) to ascertain whether the handler is called. Last, but not least, one thing lacking in your handler: after you respond to a key set Key to 0 to prevent its propagation to "downstream" handlers. ---------------------------------------------------------------------- Weitentaaal · 2021-07-23 06:02 Changed my code to 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    //Focus von anderen Componenten nehmen   KeyPreview:= True;   case Key of     VK_UP: if (ssShift in Shift) then MoveWholeUnit(dirBackward) else MoveWholeUnit(dirUp);     VK_DOWN: if (ssShift in Shift) then MoveWholeUnit(dirForward) else MoveWholeUnit(dirDown);     VK_LEFT: MoveWholeUnit(dirLeft);     VK_RIGHT: MoveWholeUnit(dirRight);  end;  Key:= 0;   KeyPreview:= False;  Now it does the Exact opposite of what i wanted to have Sorry for the Useless Description last time just thought i have the Code like u explained and it didn't work .. even with all settings. EDIT: I obviously placed "KeyPreview:= True;" wrong ... where should i put it ? if i put it at start it wont allow me to Press any Key. EDIT2: Deleted every keyPreview. But now i cant press anything (Key := 0 was the Problem). Still don't know how to use Keypreview EDIT3: This did the Job : 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 TStartUp.FormKeyDown(Sender: TObject; var Key: Word;  Shift: TShiftState);begin  //Focus von anderen Componenten nehmen  case Key of     VK_UP: if (ssShift in Shift) then MoveWholeUnit(dirBackward) else MoveWholeUnit(dirUp);     VK_DOWN: if (ssShift in Shift) then MoveWholeUnit(dirForward) else MoveWholeUnit(dirDown);     VK_LEFT: MoveWholeUnit(dirLeft);     VK_RIGHT: MoveWholeUnit(dirRight);  end;   case Key of     VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT: Key:= 0;  end;end;   EDIT4: Ok  no it didn't. It Helped me to move Object without Problems but took my possibility to use Arrow Keys in generall EDIT5: All i acheived were Some workarounds wich do NOT do what i wanted but get Close to it. 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 TStartUp.FormKeyDown(Sender: TObject; var Key: Word;  Shift: TShiftState);begin   If CbDeviceType.Focused then begin     RemoveFocus(True);     Exit;   end;   //Focus von anderen Componenten nehmen  case Key of     VK_UP: if (ssShift in Shift) then MoveWholeUnit(dirBackward) else MoveWholeUnit(dirUp);     VK_DOWN: if (ssShift in Shift) then MoveWholeUnit(dirForward) else MoveWholeUnit(dirDown);     VK_LEFT: MoveWholeUnit(dirLeft);     VK_RIGHT: MoveWholeUnit(dirRight);  end;   //Dies soll davon abhalten dass nebenbei ComboBoxen ihren Wert ändern  case Key of     VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT: Key:= 0;  end;end; ---------------------------------------------------------------------- dseligo · 2021-07-23 22:27 Quote from: Weitentaaal on July 23, 2021, 08:02:57 amEDIT: I obviously placed "KeyPreview:= True;" wrong ... where should i put it ? if i put it at start it wont allow me to Press any Key. You need to set KeyPreview in Object Inspector for your form. I put screenshot in attachment.