I have an application which works with a barcode scanner. The barcode scanner communicates with the computer in a way an external keyboard would, so I've put a keydown event listener on the DOM to capture input from the barcode scanner and mark a corresponding item in the dom. Now my problem is, anytime a barcode is read in, the dom seems to refresh and clear all selection. Can someone help? This is my code. All of this is been done in electron by the way
document.addEventListener("keydown", (e) => {
if (e.key === "" || e.key === "Control") {
return
}
buffer.push(e.key);
setTimeout(() => {
if (buffer.length > 0) {
buffer.forEach((char) => {
string = string + char
})
if (buffer.length >= 12) {
const tableRows = document.querySelector("tbody").querySelectorAll("tr");
tableRows.forEach((row) => {
const barcode = row.querySelector(".td_Barcode--hidden").innerText;
if (barcode === string) {
toggleRowCB(row)
}
})
} else {
console.log(buffer.length);
}
}
buffer = [];
string = "";
}, 500)
})