Recent

Author Topic: Win 10 IoT Getting USB Barcode reader data without holding focus on TEdit  (Read 1329 times)

ermok

  • Newbie
  • Posts: 5
Hey.

I have another problem with sneaky win 10.
I need to get barcode reader data always, so far i havent found good solution. Win does not allow open keyboard as HID device.

System at the moment: Small PC, no internet, no display, no keyboard, no other user input. Only Barcode reader.
All windows messages and notifications are turned off.

Cursor is automatically set to edit box at program start, also program has implemented automatic focusing system in case application will be deactivated.

But windows is sneaky bastard. It may trigger some ridicolus message or notification, eg lets set thing up, lets finish setup, better user experience and so on.
My program triggers automatic focus gain, application will be activated, takbar icon is yellow colored but that poor input will not transfer where it meant to be and no scanner data.

Refocusing code is:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Timer1Timer(Sender: TObject);
  2. var
  3.   I: LPInput;
  4. begin
  5.  
  6.   Timer1.Enabled:= False;// timer activated focus regain code
  7.  
  8.   if Self.cbAutoFocusHold.Checked = False then // checkbox unchecked, ignore auto focusing
  9.     Exit;
  10.  
  11.   I := nil;
  12.   try
  13.     // Hack #2: send myself some dummy input
  14.     GetMem(I,SizeOf(Input));
  15.     FillChar(I^, SizeOf(Input),$00); // empty input structure
  16.     SendInput(1, I, SizeOf(Input));
  17.     SetForegroundWindow(Application.MainForm.Handle);
  18.   finally
  19.     if I <> nil then FreeMem(I,SizeOf(Input));
  20.   end;
  21.   SetActiveWindow(Self.Handle);
  22.   edBarcodeInput.SetFocus;
  23.   memLog.Lines.Add('refocused');
  24. end;
  25.  

Maybe there is something wrong with the focus grab code, but better way is get barcode data directly.
Also there is no VSP entry in device manager.

Any help/idea/sugestion is very welcomed.



avra

  • Hero Member
  • *****
  • Posts: 2523
    • Additional info
Besides providing a keyboard driver, many bar code readers also provide DLL based SDK that you can use instead. However, if that is not the case then you might consider using system or form based keyboard hook.

https://forum.lazarus.freepascal.org/index.php?topic=54701.0
https://forum.lazarus.freepascal.org/index.php?topic=11971.0
https://forum.lazarus.freepascal.org/index.php/topic,54914.0.html
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Zvoni

  • Hero Member
  • *****
  • Posts: 2608
Remember: Many Barcode-Readers offer a (simulated?) "serial COM-Port (RS232)"-Mode....
Then it's just reading the Byte-"Stream" coming in there..... independant, if the App has Focus or not....

https://wiki.freepascal.org/Hardware_Access#Serial_Communication
« Last Edit: January 26, 2024, 01:44:39 pm by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

ermok

  • Newbie
  • Posts: 5
Re: Win 10 IoT Getting USB Barcode reader data without holding focus on TEdit
« Reply #3 on: February 03, 2024, 12:28:45 pm »
Yes, I posted the question and walked away from computer and then I figured out that I can reconfigure scanner to act as usb-serial port.
Novadays scanners have everything built in - just scan specific code supplied by vendor and voila, now it is usb-serial device.
Also serial is something I use every day, I mostly work with microcontrollers (Microchip PIC series, ARM Embedded and so on) and serial is main communication interface with PC.
But I will study key hook too, for the future projects.

Thanks for answering my question.

 

TinyPortal © 2005-2018