Disabling keyboard focus for a control (TButton especially)? lazarus / 31-LCL ---------------------------------------------------------------------- dahaiou · 2012-07-27 09:58 Is it possible to disable focus for a control (TButton especially)? I have already set Tabstop := False for all these buttons, and it works in the sense that they are passed over when the Tab-key is pressed. But when I use the arrow-keys, it seems these buttons still receive focus, and the button faces are annoyingly focus- highlighted one after the other as I keep hitting an arrow key. I am using the arrows for specific things in the program and have them intercepted by the main form. This is working as I want, but it's unrelated to the buttons on the form, and I don't want to see them flickering as I press the arrows. There is a TabOrder property that holds an Integer value. I was trying to take the buttons out of the TabOrder sequence entirely by setting this to an empty string but the IDE won't allow it. I might be missing something vary basic here (?). Note: There is no problem with the functionality of the buttons as such. I am intercepting the enter-key as well and a button press is never generated from the keyboard. It's just the annnoying highlighting I need to get rid of. How can I prevent it? PS. In case it matters, I am using Lazarus 0.9.30.4/32bit under Win7-64. ---------------------------------------------------------------------- dahaiou · 2012-07-27 12:38 An afterthought: If focus cannot be disabled, just disabling the hightlighting would do too. Is this a tough one perhaps, since no-one has come up with anything? Any ideas? ---------------------------------------------------------------------- Zoran · 2012-07-27 13:00 I don't know if it can be done. Anyway, the workaround for you is using TSpeedButton instead of TButton controls. TSpeedButton does not descend from TWinControl, so it never receives focus. ---------------------------------------------------------------------- dahaiou · 2012-07-27 14:31 Thanks, I changed them all to TSpeedButton and it seems to do the trick. No more highlighting. Only thing that happens now, when I use the Up/Down arrow keys, is that once in a while all these buttons flicker briefly, like they are redrawn for no reason. I guess this might be an effect of the parent TGroupBox receiving focus. This is a smaller nuisance than the highlighting though. And it's only happening with the Up/Down arrow keys, not Left/Right. Strange. ---------------------------------------------------------------------- CM630 · 2017-03-16 10:03 A few years later- maybe there is already asolution for that? I want to fully disable changing focus with the arrows on the form components. Maybe I could put something in the OnKeyDown event of the form (I have keypreview enabled). ---------------------------------------------------------------------- Zoran · 2017-03-16 11:03 Quote from: CM630 on March 16, 2017, 11:03:27 am A few years later- maybe there is already asolution for that? I want to fully disable changing focus with the arrows on the form components. Maybe I could put something in the OnKeyDown event of the form (I have keypreview enabled). To disable changing focus only with arrows set Form1.KeyPreview to True and Form1.OnKeyDown 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 procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState  );begin  if Key in [VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN] then    Key := 0;end;  The focus will still change with Tab. If you want to disable tab as well, add VK_TAB in the set. ---------------------------------------------------------------------- CM630 · 2017-03-16 13:11 Thanks, it works! I only changed it to if (Key >36) and (key <41) then  Key := 0; because VK_ requred uses  ... windows... which causes some problems. ---------------------------------------------------------------------- Zoran · 2017-03-16 20:21 Quote from: CM630 on March 16, 2017, 02:11:55 pmThanks, it works! I only changed it to if (Key >36) and (key <41) then  Key := 0; because VK_ requred uses  ... windows... which causes some problems. No, VK constants can be found in LCLType unit. There is even a FAQ about it http://wiki.lazarus.freepascal.org/Lazarus_Faq#Virtual_key_constants ---------------------------------------------------------------------- Thaddy · 2017-03-16 20:30 Correct. I often wonder why people never read documentation.