1
votes

i am trying to upgrade a program from Delphi7 to DelphiXE8.

In the programm there are some TEdit fields. You could input data in that fields via keyboard or a usb scanner. The usb scanner emulates a keyboard and works fine in all other programs. (Same program in Delphi7, Firefox, Editor, etc.......)

If I use the scanner in Delphi XE8 the TEdit field doesn't get correct data. If I trigger a KeyDown event I see that there are many Key 16/17/18 coming in but KeyChar is always #0.

Same Problem with TMemo.

I just tried something different:

In a VCL project the scanner works fine. In a FMX project the scanner fails.

The scanner is a Birch BF-481BU/N.

Any ideas what could solve that problem?

3
Hi! Are you developing for Windows?Sergey Krasilnikov
Does your scanner support setting of delay between keys input? Have you tried to increase the delay?Sergey Krasilnikov
Until now, it is only for windows. But in the future we wonna port it to other devices.Benedikt
It set the gap up to 99ms.... same result.Benedikt
In Delphi7 and XE8-VCL there is a windows message WM_CHAR which results in a OnKeyPressed event. The USB-Scanner sends this WM_Char for the actual key. But FMX.Platform.Win line 2328 never gets triggered in the FMX project.Benedikt

3 Answers

0
votes

My scanner has a Caps Lock setting.

Auto
Alt+Keypad
Caps Lock Off
Caps Lock On

With "Auto","Off","On" the scanner works fine with FMX. With "Alt+Keypad" the scan fails in FMX.

0
votes

I tried with a normal USB Scanner (Keyboard wedge) with this code that works fine.

procedure TForm2.Edit1KeyDown(Sender: TObject; var Key: Word; var KeyChar: Char;
  Shift: TShiftState);
begin

 if KeyChar = #13 then ShowMessage('Your code is ' + Edit1.Text);

end;

Alt + Keypad is used to enter particular chars typing the ascii code.
As an example if you press ALT + 126 the result will be "~"
So probably you have to remove the Alt+Keypad settings on your scanner.
0
votes

I had this problem with a game I'm building. It seems that the keycode is getting "handled" and set to null before it ever even gets to the form. It looks like they are only passing things through when the ALT or CTRL keys are pressed.

To solve this particular problem, I commented out a line in FMX.Platform.Win

procedure CurrentChar(Msg: tagMsg; var Key: Word; var Ch: WideChar; var Shift: TShiftState);
begin
  Key := wParam;
  Ch := WideChar(Msg.wParam);
  Shift := KeyDataToShiftState(lParam);
  if (Ch >= ' ') then
  begin
    if ((Shift * [ssAlt, ssCtrl]) = [ssAlt, ssCtrl]) then
    begin
      // AltGr + Char (in German keyboard)
      Shift := Shift - [ssAlt, ssCtrl];
    end;
    //WHYYYY?!?!?!?!?!?!?
    //if (([ssAlt, ssCtrl, ssCommand] * Shift) = []) then
    //  Key := 0;
  end;
  if ((([ssAlt, ssCtrl, ssCommand] * Shift) <> []) or (Ch < ' ')) and (Key > 0) then
    Ch := #0;
end;

What I did FIRST though is I copied FMX source folder into your own private source tree and built it from there. Then your apps will build with any minor patches you put into it, but it is simpler than installing hacked design-time packages.

Once you have your own private FMX source, then you can start hacking it (which you will have to do from time to time).

The first thing you should do when starting a new project, is copy the FMX source folder into your own private source tree and build from there.

FMX still has a way to go before it is a comprehensive cross platform solution, but it is getting closer, so you'll have to mess with it occasionally. Using similar approaches, I added Android pen support, fixed some BLE issues... you'll probably come across your own things.