{"id":15680236,"url":"https://github.com/denyncrawford/native-barcode-scanner","last_synced_at":"2025-08-12T10:07:03.271Z","repository":{"id":57308227,"uuid":"321242639","full_name":"denyncrawford/native-barcode-scanner","owner":"denyncrawford","description":"Native barcode sacanner device driver for Node.","archived":false,"fork":false,"pushed_at":"2020-12-15T18:53:00.000Z","size":140,"stargazers_count":6,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-09T11:44:03.543Z","etag":null,"topics":["barcode","barcode-scanner","keyboards","native","native-events","node"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/denyncrawford.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-14T05:24:29.000Z","updated_at":"2023-09-17T04:36:48.000Z","dependencies_parsed_at":"2022-09-07T01:01:34.375Z","dependency_job_id":null,"html_url":"https://github.com/denyncrawford/native-barcode-scanner","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/denyncrawford/native-barcode-scanner","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denyncrawford%2Fnative-barcode-scanner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denyncrawford%2Fnative-barcode-scanner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denyncrawford%2Fnative-barcode-scanner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denyncrawford%2Fnative-barcode-scanner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/denyncrawford","download_url":"https://codeload.github.com/denyncrawford/native-barcode-scanner/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denyncrawford%2Fnative-barcode-scanner/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269756387,"owners_count":24470562,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["barcode","barcode-scanner","keyboards","native","native-events","node"],"created_at":"2024-10-03T16:40:59.388Z","updated_at":"2025-08-12T10:07:03.220Z","avatar_url":"https://github.com/denyncrawford.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Native Barcode Scanner \n\nIt is a simple utility inspired by [simple-barcode-scanner](https://github.com/hadeeb/simple-barcode-scanner) but made as a native and global keyboard scanner driver for Node, this means that it doesn't depend on the browser and it listens even when no GUI/UI is focused. \n\nMost barcode scanners act like a keyboard, NBS handles this by listening for native events without using the DOM API. This is useful for scanning without focusing on any screen and works for multiple devices.\n\n### Why?\n\nI needed a way to use multiple scanners on a PC without depending on one window being foused. It is not viable / reliable to use on electron and browser runing on machines used by several users at time.\n\n**Don't scare!** NBS is pretty simple too and it can be used with a sigle scanner on a simple app :D, but with the security that data is not getting lost anymore.\n\n### How?\n\nBarcode scanners are HID devices also, but there's one trick, they are **FORBIDEN** by some systems... Basically they doesn't allow HID connections for keyboards and mouses for security reasons. So while looking for a solution I found that `node-hid` is not that useful and we can't take a direct connection from the device. \n\n**So, how it is native?** Well, this is the bittersweet part: We use Java to capture native/global keys and keybindings events, and yeah... you have to install it :/ but it is not that hard :B (I mean, probably you have it already installed, you know... minecraft). This is because neither Node or Deno support native events for keyboards and mices. Anyway, it is incredibly fast as well. \n\n\u003e I'm currently looking for a C++ solution like ioHook but its installation is a little bit cursed, and it crashes all the time (at least for me and my builds) if you want to contribute with a native way to listen to key events and pipe them to JS please make a PR :D.\n\n##  📦 Install\n\n```bash\nnpm install --save native-barcode-scanner\n```\n\n```javascript\n// using ES6 modules\nimport BarcodeScanner from \"native-barcode-scanner\";\n\n// using CommonJS modules\nconst BarcodeScanner = require(\"native-barcode-scanner\");\n```\n\n## 🖥️ Usage\n\nYou can use NBS as a global listener or as a dedicated device listener.\n\n### Basic (global):\n\n\u003e This will listen to all devices and will catch all codes from the multiple emitting devices. This is the way if you have just one device or if your device doesn't allow prefixing. \n\n```javascript\nimport BarcodeScanner from \"native-barcode-scanner\";\n\nconst options = {...foo}\n\nconst scanner = new BarcodeScanner(options);\n\n// Add a global listener\nscanner.on('code', code =\u003e {\n  console.log(code);\n});\n\n// Remove the listener\nscanner.off();\n```\n\n### Dedicated device:\n\nAs I said before, some devices allow code prefixing functions and you can use it to scope the NBS events.\n\nTo do this, you have to prefix your device with your choosen device ID string and then specify it at `options.devicePrefix`.\n\n\u003e **Note**: NBS doesn't prefix your device, you must use one that does. Please read your device user guide. \n\n```javascript\nimport BarcodeScanner from \"native-barcode-scanner\";\n\nconst options = {\n  devicePrefix: 'id1'\n}\n\nconst scanner = new BarcodeScanner(options);\n\n// Add a global device scoped listener\nscanner.on('code', code =\u003e {\n  // This only works for the device(s) prefixed with id1\n  console.log(code);\n});\n\n// Remove the listener\nscanner.off();\n```\n\n\u003e **Note**: We un-prefix the code for you ;) you can log it as clean as it is on the paper.\n\n# 🧰 API\n\n### BarcodeScanner\nCreates an instance of Scanner to use the code events.\n\n**Parameters**\n\n- `Options` **Object**\n\n  - `latency` **Number** Max time duration (in ms) between consecutive inputs\n\n    _default: `50`_\n\n  - `minLength` **Number** Min length of a valid barcode\n\n    _default: `3`_\n\n  - `endKeys` **string** Key name indicating end of barcode\n\n    Refer [Key Values | MDN](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)\n\n    _default: `[\"Enter\"]`_\n\n  - `validKey` **RegExp** Regular expression to check for a valid key in barcode\n\n    Refer [Key Values | MDN](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)\n\n    _default: `/^\\w$/`_\n  \n  - `devicePrefix` **string** Prefix ID for device scoped events\n\n    _default: `null`\n\nReturns **Scanner**\n\n### Scanner\n\n- #### on\n\n  Starts listening for barcode scans and add/replace the listener\n\n  **Parameters**\n\n  - eventName **string** Event string must be `code`\n\n  - handler **Function** Function to call on completion of barcode scan\n\n    _Recieves the scanned code of the last input as parametes_\n\n- #### off\n  Stop listening for barcode scans and remove the listener\n  \n# 🌐 Using on web\n\nPlease if you are on browser use [simple-barcode-scanner](https://github.com/hadeeb/simple-barcode-scanner)\n\nIf you want the multi-device update use my fork [@denyncrawford/simple-barcode-scanner](https://github.com/denyncrawford/simple-barcode-scanner/tree/device-instance)\n\n# 👥 Credits\n\nDeveloper: [denyncrawford](https://github.com/denyncrawford/)\n\nThis idea couln't be possible without [simple-barcode-scanner](https://github.com/hadeeb/simple-barcode-scanner), thanks.\n\n# 🏗️ Contributing\n\n1. Create an issue related to the problem or idea and check if it is viable\n2. Fork it :D\n3. Create a new branch with your changes.\n4. Make a PR.\n\n# 📜 License\n\nMIT License\n\nCopyright (c) 2020 Miguel Rangel\n\n[See full licese](https://github.com/denyncrawford/native-barcode-scanner/tree/main/LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenyncrawford%2Fnative-barcode-scanner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdenyncrawford%2Fnative-barcode-scanner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenyncrawford%2Fnative-barcode-scanner/lists"}