How to detect Enter key press on Delphi form without interfering with any user interface controls on the form.
I am trying to read the output of a barcode scanner in a Delphi form. The scanner generates keypress events for each digit of the barcode as if a numeric key on the keyboard had been pressed and then an Enter keypress to indicate the barcode has been read.
The problem is this - I must differentiate between scanner and keyboard without affecting user interface.
I build up a buffer containing the barcode every time a numeric digit keypress is detected and when the enter key press detected I test to see if buffer is the length of the barcode- if so I assume a barcode was scanned and eat the enter key press. If the enter key was pressed and the barcode buffer is not the length of the expected barcode I assume enter was pressed on another user control. I cannot read the barcode into a textbox - a common method for reading such scanners - as the barcode is not relevant to the user and this requires the textbox having focus. The requirements are that a scan can occur anytime/anywhere while the form is open.
I have solved this by using the solution proposed by @Tlama at following link.