2
votes

I have a large firemonkey android application which is designed for use primarily on barcode scanner devices, but must also be usable on e.g. an android phone (for testing). When used on a barcode scanner device, which typically has a physical keyboard, we suppress the virtual keyboard by setting VKAutoShowMode to TVKAutoShowMode.Never.

This works just fine for most of the Tedit components. However, for 1 or 2 of these - which are to all intents and purposes "the same" as the others - the virtual keyboard pops up when the key press is received from the physical keyboard. And furthermore, it is not easily dismissed by using the return key with KillFocusByReturn set on the relevant Tedit.

I can work around the problem using the Android Language & input settings to effectively disable the virtual keyboard completely, but this is less than ideal as in some fields we do want the soft keyboard for simpler alpha input.

I can also achieve a partial workaround by calling up our "HideVirtualKeyboard" routine within an onkeyup event for the problem Tedit(s), but this looks silly as the keyboard flashes up and then disappears. Also, if one then moves to another TTabItem within the application after giving focus to the problem Tedit, a key press on the physical keyboard will pop the virtual keyboard up and special action has to be taken to get rid of it.

I would appreciate any suggestions.

1

1 Answers

0
votes

I have done a few projects using RFID readers, and I ended up taking control of the keyboard myself where I needed to do so. Here is same code from one of my projects:

else if TabControl1.ActiveTab = tsRFID then
  begin
    {$ifdef NORFIDTYPING}
    VKAutoShowMode := TVKAutoShowMode.Never; // hide virtual keyboard
    {$endif}

It should be noted that the following code doesn't always tell the truth:

function TfrmAppMain.KeyBoardVisible: Boolean;
var
  FService : IFMXVirtualKeyboardService;
begin
  Result := False;
  TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardService, IInterface(FService));
  if (FService <> nil) and (TVirtualKeyboardState.Visible in FService.VirtualKeyBoardState) then
    Result := True;
end;