Barcode Scanner Emulator
Barcode Scanner Prefix vs Suffix: Complete Guide
A prefix is data or a control sequence a barcode scanner sends before the decoded barcode. A suffix is what it sends after that value. The same model can be set to different prefixes and suffixes, and a serial scanner does not deliver them the same way a keyboard-wedge scanner does.
A barcode scanner prefix is sent before the decoded value. A suffix is sent after it. One scanner might produce this sequence:
Prefix: STX
Barcode: 123456789
Suffix: ENTER
STX in a manual often means the control character, not the three letters S, T, and X. ENTER on a keyboard-wedge scanner is usually the Enter key, not the two characters CR and LF inserted into a text field. Which of those you receive depends on the model, the interface, and the application. No setting is universal.
The ENTER vs TAB suffixes guide stays on choosing and troubleshooting those two terminators. This guide is about the frame around the barcode: what comes before, what comes after, and how a web application should read both.
What Is a Barcode Scanner Prefix?
A prefix is a configured sequence the scanner transmits before the payload. The payload is the text the symbology decoded, such as 123456789. The prefix is not part of that decode unless the scanner was set to add it.
Common uses:
- Mark the start of a message. Serial and terminal protocols sometimes send a control character, often called STX, so the host knows a new frame has started.
- Name the symbology. With the AIM symbology identifier enabled, a scanner can send a short printable prefix such as
]C1for Code 128 or]E0for EAN before the digits. The application can branch on that identifier. - Route input in older POS or terminal software. A fixed code before the data told the host which field or device the scan belonged to.
- Tag a particular station. Two scanners can be given different printable prefixes so a log can show which lane sent the code.
A printable prefix is ordinary characters. They appear in a text field at the front of the string. A control-character prefix, such as STX (0x02), is not the letters S, T, and X. A keyboard-wedge scanner may be unable to type that control character at all. A serial scanner can send it as a byte. Read the manual for the model you have before you write code that expects one or the other.
A prefix does not prove that a scanner produced the input. A person, a macro, or the Barcode Scanner Emulator can type the same characters. Treat a prefix as framing you configured, then validate the payload the way you validate any other user input.
What Is a Barcode Scanner Suffix?
A suffix is a configured sequence sent after the payload. Its usual job is to tell the application that the scan is finished, or to move focus. Scanners differ. Some offer Enter, Tab, CR, LF, CR+LF, a custom string, or nothing. Some offer only one or two of those.
ENTER. The Enter key. In a browser this is a keyboard event, event.key === "Enter". It is not inserted into a normal text input.
TAB. The Tab key, event.key === "Tab". The browser moves focus to the next control. The key is not inserted into the field.
CR. Carriage return, ASCII 0x0D. On a serial or terminal interface this can be a real byte after the payload. On a keyboard wedge, a setting labeled CR or carriage return usually means the Enter key. The browser still reports Enter. The field value does not gain a CR character.
LF. Line feed, ASCII 0x0A. It is a different control character from CR. On a serial stream it can be its own byte. A keyboard wedge does not have a standard Line Feed key the way it has Enter and Tab. Do not assume a menu item named LF types a visible character or a second Enter.
CRLF. CR followed by LF, the two bytes 0x0D 0x0A. Some serial and terminal hosts expect that pair as the end of a line. A browser text field does not store that pair when someone presses Enter.
Custom characters. A printable suffix such as # or a short code is typed after the barcode, so it becomes part of the string unless the application removes it. A custom control character follows the same split as STX: bytes on a serial port, keystrokes on a wedge, and only the keystrokes the keyboard interface can actually send.
ENTER, CR, and LF are related names for "end of line" in manuals. They are not interchangeable in every application. A wedge scanner, a serial scanner, Notepad, and a web form can each show a different result for a setting with the same name.
Prefix vs Suffix
| Feature | Prefix | Suffix |
|---|---|---|
| Position | Before the barcode data | After the barcode data |
| Purpose | Mark the beginning or label the input | Mark completion or trigger an action |
| Example | STX, or a printable AIM identifier such as ]C1 |
ENTER, TAB, or a printable character such as # |
| Common use | Frame or identify the scan | Submit a form or move focus |
| In a text field | Printable characters sit at the start of the value | Printable characters sit at the end. Enter and Tab do not |
| Identity | A configured marker anyone can type | A configured marker anyone can type |
Strip a prefix or a custom suffix only when you configured that exact sequence and the stored record should not include it. Leave an AIM identifier in place until the application has a rule for it.
ENTER, TAB, CR, and LF
These names show up on configuration sheets. The receiving side sees either keystrokes or bytes, depending on the interface. The HID keyboard wedge guide describes the keystroke path. A serial port is a different path: the application reads bytes, and focus does not choose where they go.
ENTER
On a keyboard-wedge scanner, ENTER is the Enter key. Inside a one-line text field, current browsers use that key to submit the enclosing form. A lookup box can commit the scan on that event. A multi-field form can submit before later fields are filled. Call preventDefault() on the submit event, or on the Enter keydown, when the page should keep the value and stay put. Handle Enter in one place. A keydown listener and a submit listener that both accept the scan will record it twice.
Some scanners send NumPad Enter. event.key is still "Enter". event.code may be "NumpadEnter" rather than "Enter". Test event.key if both keys should commit the field.
The ENTER vs TAB suffixes guide compares those two choices for POS and web forms. Barcode Scanner Missing ENTER covers a scanner that types the barcode and then stops.
TAB
TAB is the Tab key. The browser moves focus after keydown. Read the field in that keydown handler, while it still has focus, and leave the default action in place when the next control should receive the cursor. preventDefault() keeps focus on the current field.
Shift+Tab is the same key with Shift held. A scanner Tab suffix is Tab without Shift. Ignore event.shiftKey if keyboard users must be able to move backward through the form.
CR
Carriage return moves a cursor to the start of the line in a terminal. The byte is 0x0D. A serial scanner can append that byte to the payload. A keyboard-wedge setting named CR typically sends the Enter key instead of inserting 0x0D into the text. Pressing Enter in a browser input does not write a CR character into input.value.
If the host is a terminal or a COM-port listener, look for the byte. If the host is a web page, look for event.key === "Enter".
LF
Line feed moves a terminal cursor down one line. The byte is 0x0A. Some hosts treat LF alone as the newline. Others ignore it unless CR came first. A wedge scanner that lists LF as a suffix may send a key the operating system does not turn into a line break, or it may send nothing a text field will keep. Capture the key in the Keyboard Event Tester before you handle a supposed LF in application code.
CRLF
CRLF is the two-control sequence CR then LF. Windows-style text files and many serial devices use it as one newline. A configuration page that says "CRLF suffix" means the scanner will try to send that pair after the payload on the interface it is using.
In a browser, pressing Enter does not produce a literal CRLF sequence inside a text input. The form receives a keyboard event. A <textarea> may insert a newline when the user presses Enter, and that newline is the browser's own editing behavior, not proof that the scanner emitted the bytes 0x0D 0x0A. A serial reader can receive those two bytes and should treat them as the terminator only if that scanner was configured to send them. Do not strip CR or LF from the middle of a payload that is allowed to contain them.
How Prefixes and Suffixes Affect Web Applications
A keyboard-wedge scan is a burst of keystrokes into the focused control. The page does not open the scanner. If focus is on another field, the prefix, the barcode, and the suffix all go there.
keydown fires for every key, including Enter and Tab, before the browser inserts a character or moves focus. event.key is the character or key name after the operating system applies the keyboard layout. Printable prefix and suffix characters show up in the field through the input event. Enter and Tab do not.
The listener below commits the field when Enter arrives. It does not add a suffix the scanner omitted. If the scanner sends no Enter, the value stays in the field until something else reads it.
const field = document.querySelector('#barcode')
if (!(field instanceof HTMLInputElement)) {
throw new Error('Barcode field was not found.')
}
field.addEventListener('keydown', (event) => {
if (event.key !== 'Enter') {
return
}
event.preventDefault()
const value = field.value.trim()
if (!value) {
return
}
console.log(value)
field.value = ''
})
Focus #barcode before the scan. preventDefault() stops an ancestor form from submitting a second time. If the input is not inside a form and you want the native submit, omit preventDefault().
Without a suffix, wait for an explicit action: a button, a later Enter from the operator, or the next step in the workflow. An inactivity timer can treat a pause as the end of the scan. That timer is a heuristic. A slow scanner, a Bluetooth delay, or a fast typist can fall on the wrong side of it. Prefer a configured suffix when the workflow needs a definite end.
A known printable prefix can be removed after you read the value:
function withoutConfiguredPrefix(value, prefix) {
if (prefix && value.startsWith(prefix)) {
return value.slice(prefix.length)
}
return value
}
Pass only the prefix you configured, such as ']C1'. Do not strip an arbitrary number of characters from every scan.
For a full form that also handles Tab, empty input, and a second scan, see How to Test Barcode Scanners in Web Applications.
How to Configure Prefixes and Suffixes
Prefix and suffix settings live on the scanner. The key names and the way you change them are manufacturer-specific. There is no configuration barcode that works on every brand, and this guide does not print one.
Typical methods:
- Scan a configuration barcode from the manual for that exact model. The sheet is grouped by setting: suffix, prefix, keyboard layout, symbology.
- Use the vendor's configuration program, then write the result to the scanner over USB.
- Use the device management utility for that product line when you are updating many units.
After a change, scan a known barcode and compare the result with the manual's description of the setting you chose. A factory reset from a different brand can leave the scanner unchanged or put it in an unexpected mode. The Barcode Scanner Configuration guide summarizes the settings that usually matter. It does not replace the manual.
The Barcode Scanner Emulator can type a value you choose and then send ENTER, TAB, or no suffix. Put a printable prefix in that value when you need to exercise prefix handling without hardware. The emulator does not emit a serial CR/LF byte pair, and it does not read a label.
How to Test Prefix and Suffix Behavior
Use a scanner that is in keyboard mode, USB HID keyboard or Bluetooth HID keyboard.
- Connect it and wait until it shows it has power.
- Open the Barcode Input Tester.
- Click Start Test, or click the scan area. It turns blue when it is ready. The page does not take focus on its own.
- Scan a barcode whose payload you already know.
- Read the captured value and the character count. Printable prefix or suffix characters are inside that string. The Prefix line is for named keys that arrive before the first character, such as a modifier. It does not pull a typed prefix like
]C1out of the barcode text. - Check the suffix. The tester reports ENTER, TAB, or None. With Auto capture on, the result appears after Enter, Tab, or a short pause once the keys stop. Turn Auto capture off to hold the capture until you press Stop. Enter and Tab are not part of the barcode string.
- Compare that result with the configuration you intended. Then open the Keyboard Event Tester and scan again when you need each
keydownin order, includingkey,code, and timing.
The input tester records keyboard events the browser can see. It cannot read a serial port, so it cannot show CR or LF as raw bytes. A wedge test does not prove what a serial setting will send.
Troubleshooting
The scanner does not send ENTER. The barcode appears and the cursor stays in the field. The input tester reports None. The suffix is off, or it is set to something other than Enter. See Barcode Scanner Missing ENTER.
TAB moves focus unexpectedly. The scanner is sending the Tab key. That is the configured suffix. Use Enter when the form should submit, or read the value on Tab keydown when the workflow should advance. Details are in the ENTER vs TAB suffixes guide.
The form submits twice. The browser submits on Enter, and a keydown listener also accepts the scan. Keep one completion path and call preventDefault() on the other.
A prefix shows up inside the barcode. A printable prefix is part of the captured string. Either disable it on the scanner or remove that exact sequence in the application. An enabled symbology identifier is a common source of a leading ] and two more characters. A control prefix that the wedge cannot type will be missing instead of visible.
Characters are wrong. The scanner layout and the operating-system layout can disagree, which changes prefix characters and punctuation while the length stays the same. See Barcode Scanner Wrong Keyboard Layout.
The application never sees the end of the scan. There is no suffix, and the page is waiting for Enter. Add a suffix that matches the form, or complete the value on an explicit action. A timing guess will miss some real scans and accept some typing.
CR/LF differs between applications. Notepad inserts a new line when it receives Enter. A web text input keeps the barcode and fires a key event. A serial program may receive 0x0D, 0x0A, or both. Compare the interface before you change the scanner. If no application receives characters, start with Barcode Scanner Not Working.
A wider pass over focus, repeated scans, and POS flows is in How to Test Barcode Scanner Input.
Test Matrix
The configuration column is what you set on the scanner, or what you type with the emulator when the case is a keyboard suffix. The expected behavior is what the application should do. A serial CRLF case is not the same test as an Enter key in a browser.
| Configuration | Expected application behavior |
|---|---|
| No prefix, no suffix | The barcode value is received and no completion key arrives. The value stays available until the application reads it. |
| No prefix, ENTER suffix | The application receives the completion key once and stores the payload without a terminator character. |
| No prefix, TAB suffix | Focus may move to the next control. The application reads the value before that move. |
| Custom printable prefix | The prefix characters appear before the decoded data. The application keeps or removes that exact prefix on purpose. |
| Custom printable suffix | The suffix characters appear after the decoded data. Enter and Tab are keys, so they do not appear in the string. |
| CRLF sequence | A serial or terminal host processes the configured CR and LF bytes. A browser text field does not gain those bytes from an Enter keypress. |
Run the keyboard rows on the wedge scanner and, when hardware is absent, with the emulator's ENTER, TAB, and no-suffix settings. Run the CRLF row on the interface that is supposed to carry those bytes. Actual results still depend on that interface and on the application.