代码之家  ›  专栏  ›  技术社区  ›  Fabrizio RAHUL S R

如何将数字键盘点键转换为小数分隔符?

  •  0
  • Fabrizio RAHUL S R  · 技术社区  · 2 年前

    在某些应用程序中,如 Microsoft Excel ,数字键盘上的点键( VK_DECIMAL )自动转换为当前 DecimalSeparator

    Picture of a numeric keypad with an arrow pointing to the dot key

    我正在尝试实现相同的功能,但我没有找到在整个应用程序中使其工作的方法。

    1 回复  |  直到 2 年前
        1
  •  -1
  •   Fabrizio RAHUL S R    2 年前

    在表单级别,可以使用表单的 KeyPreview 财产和 OnKeyPress 事件处理程序,例如:

    function IsKeyPressed(const AKey : Word) : Boolean;
    begin
      Result := GetKeyState(AKey) < 0;
    end;
    
    procedure TMyBaseForm.FormCreate(Sender: TObject);
    begin
      inherited;
      KeyPreview := True;
    end;
    
    procedure TMyBaseForm.FormKeyPress(Sender: TObject; var Key: Char);
    begin
      inherited;
      if(IsKeyPressed(VK_DECIMAL))
      then Key := FormatSettings.DecimalSeparator;
    end;
    

    但是,此解决方案需要为所有应用程序的窗体和 不会处理任何不是从基类继承的窗体/对话框 (即:它不适用于简单的 InputQuery 任一)