ComboBox KeyDown event lazarus / 31-LCL ---------------------------------------------------------------------- andy.int · 2018-08-16 01:55 Hi, I am using the KeyDown event of ComboBox. The keys ESC, TAB, Enter have the same key value (Key= 0), is this correct? How do I get the correct key value? Thank you. Environment: Windows 10 Home lazarus-1.8.4-fpc-3.0.4-win64.exe Beginner, andy.int 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 TForm_main.ComboBox_market_KeyDown(Sender: TObject; var Key: Word;  Shift: TShiftState);beginCaption := Caption + 'KeyDown(' + IntToStr(Key ) + ') ';  // For test   case Key of  VK_F4: begin  // Disable F4         Key := 0;         end;  VK_ESCAPE: begin                                       //Key := 0;             // Do something                        end;  VK_TAB: begin                 //Key := 0;          // Do something                    end;  VK_RETURN: begin                   //Key := 0;             // Do something             end  end  // case Key ofend; ---------------------------------------------------------------------- Handoko · 2018-08-16 02:14 Hello andy.int, Welcome to the forum. I tested on Linux, this code below works for me: 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.ComboBox1KeyDown(Sender: TObject; var Key: Word;  Shift: TShiftState);begin  Caption := 'KeyDown(' + Key.ToString + ') ';  case Key of    VK_F4: begin  // Disable F4           Key := 0;           end;    VK_ESCAPE: begin               //Key := 0;               // Do something               end;    VK_TAB: begin            //Key := 0;            // Do something            end;    VK_RETURN: begin             //Key := 0;               // Do something               end  endend; ---------------------------------------------------------------------- andy.int · 2018-08-16 16:56 Hi Handoko, Thank you for your answer. I got a result after the test. When the ComboBox is pulled down, the keys ESC, TAB, Enter have the same key value (Key = 0). When the ComboBox is closed, I got ESC Key= 27 TAB Key= 9 Enter Key= 13 These are the correct key values. But I hope I can get it when the ComboBox is pulled down. Just like the Key F4. Thanks. PS. I like "Key.ToString" ^_^ ---------------------------------------------------------------------- Handoko · 2018-08-16 17:24 Quote from: andy.int on August 16, 2018, 06:56:26 pmBut I hope I can get it when the ComboBox is pulled down. Just like the Key F4. I just tested the code on a Win7 computer, it worked even when the ComboBox was pulled down. But no matter how I tried, it won't call the OnKeyDown on Linux when the ComboBox is pulled down. The behavior is OS-depended I think. Have you tried the code on Win7? ---------------------------------------------------------------------- jamie · 2018-08-16 22:40 The combo box in windows are two different controls, an TEDIT and TLISTBOX..  The two controls don't seem to act together as one like they should, the keyboard input is getting captured by the EDIT box until you select something in the list box and when you hover over the list box you don't receive mouse messages...   To get better control over the box I've found using the OwnerDraw seems to work  Try setting the Style to OwnerDraw and handle the OnDrawItem, I Think you should be able to receive all after that... ---------------------------------------------------------------------- andy.int · 2018-08-17 01:18 Hi jamie, I tried it, just like you said. Thank you for your advice. Now I am trying to use the OnDrawItem event... To Handoko, I have tried different OS, Win8: Same as Win10. Win7: none WinXP: (Rebuild code) Same as Win10. Thank you so much.