OS X 上的 Lazarus OnKeyPress

Lazarus OnKeyPress on OS X

我在 OS X Yosemite 上使用 Lazarus 1.2.6,我的问题是,当我在每个对象中禁用 TabStop 时,我写了很少的我自己的代码(因为需要循环制表符),但使用 #9(tab) 它不起作用。与任何其他键一起使用。

procedure TForm1.ListBox1KeyPress(Sender: TObject; var Key: char);
begin
  if Key = #9 then
  form1.ActiveControl:=button4;
end;  

您的问题是由于 OnKeyPress 仅处理可打印的 ASCII 字符引起的。为了处理制表键等不可打印的符号,您应该使用 OnKeyDown 事件。

您的处理程序可能如下所示:

procedure TForm1.ListBox1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  if Key = VK_TAB then
  form1.ActiveControl := button4;
end;

为了访问 VK_TAB,您应该将 LCLType 添加到您的 uses 子句中。当然,这个过程应该被定义为你的控件或表单的 OnKeyDown 事件的处理程序。

参考http://wiki.lazarus.freepascal.org/LCL_Key_Handling and http://lazarus-ccr.sourceforge.net/docs/lcl/lcltype/index-2.html