{"id":15198681,"url":"https://github.com/xitanggg/node-insert-text","last_synced_at":"2025-08-17T11:05:57.577Z","repository":{"id":214113319,"uuid":"735708525","full_name":"xitanggg/node-insert-text","owner":"xitanggg","description":"A simple Node.js util that allows you to programmatically insert text on desktop","archived":false,"fork":false,"pushed_at":"2024-07-05T00:05:31.000Z","size":1216,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-09T00:39:10.567Z","etag":null,"topics":["automation","desktop","electron","native-addon","node"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@xitanggg/node-insert-text","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/xitanggg.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-25T22:50:54.000Z","updated_at":"2024-12-21T16:57:48.000Z","dependencies_parsed_at":"2024-06-16T04:29:58.528Z","dependency_job_id":"2ffe8c30-abe1-4b83-8820-c25965c90147","html_url":"https://github.com/xitanggg/node-insert-text","commit_stats":null,"previous_names":["xitanggg/enigo-node-insert-text","xitanggg/node-insert-text"],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/xitanggg/node-insert-text","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xitanggg%2Fnode-insert-text","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xitanggg%2Fnode-insert-text/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xitanggg%2Fnode-insert-text/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xitanggg%2Fnode-insert-text/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xitanggg","download_url":"https://codeload.github.com/xitanggg/node-insert-text/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xitanggg%2Fnode-insert-text/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270837583,"owners_count":24654391,"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-17T02:00:09.016Z","response_time":129,"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":["automation","desktop","electron","native-addon","node"],"created_at":"2024-09-28T01:24:14.162Z","updated_at":"2025-08-17T11:05:57.551Z","avatar_url":"https://github.com/xitanggg.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node Insert Text\n\nThis package provides a simple Node.js util that allows you to programmatically insert text on desktop.\n\n- Support Windows and Mac\n  - Mac: Need to grant accessibility permission to the calling app (`Settings` -\u003e `Privacy \u0026 Security` -\u003e `Accessibility`) to call Apple's [Core Graphics framework](https://developer.apple.com/documentation/coregraphics) to post [CGEvent](https://developer.apple.com/documentation/coregraphics/cgevent) to insert text\n- Require Node.js \u003e= 10\n\n## 📦Installation\n\n```bash\nnpm i @xitanggg/node-insert-text\n```\n\n## ℹ️Usage\n\n```typescript\nimport { insertText } from '@xitanggg/node-insert-text';\n\ninsertText('👋Hello World! This line is inserted programmatically🤖');\n```\n\n`insertText` accepts 3 arguments\n\n1. `text` - Text to be inserted\n2. `insertWithPaste` - An optional boolean that sets whether to insert text with the paste method. Default to false. (Setting true to use the paste method is useful to bypass some limitations in the default insert method. For example, the default insert method may not work for some apps, and in Mac, it doesn't work when certain key, such as `Cmd`, is pressed during insert.)\n3. `arrowKeyToClickBeforeInsert` - An optional string that sets which arrow key to click before inserting text. Can be either \"left\" or \"right\". Default to None.\n\n## 💡Implementation\n\n**Core Logic**\n\nThe implementation is written in Rust and is ~200 lines of code in a single file `/src/lib.rs`.\n\nThe happy path is a wrapper of the `text` function of [enigo](https://github.com/enigo-rs/enigo), which is a cross platform input simulation library in Rust. The default behavior simply calls `enigo.text` to perform text insertion, which works for most use cases.\n\nHowever, `enigo.text` has its limitations: 1. it may not work for some apps, and 2. In Mac, it doesn't work when certain key, such as `Cmd`, is pressed during insert [(issue link)](https://github.com/enigo-rs/enigo/issues/297). Therefore, an alternative option `insertWithPaste` is provided to insert text via clipboard paste in a 5 steps process:\n\n1. Save clipboard existing text or image\n2. Clear clipboard\n3. Set text to be inserted to clipboard\n4. Simulate `Ctrl + V` (`Cmd + V` in Mac) keyboard input to paste text from clipboard\n5. Restore clipboard previous text or image to minimize side effects to users\n\n**Dependencies**\n\nIt uses [Arboard (Arthur's Clipboard)](https://github.com/1Password/arboard) to perform clipboard operation and [enigo](https://github.com/enigo-rs/enigo) to perform keyboard input simulation.\n\nArboard supports getting and setting clipboard text and image, which should satisfy most use cases. But it is worth noting that it doesn't support other clipboard contents, e.g. html, rtf, file. A `paste` method is provided for those who would like to implement custom logics to save and restore clipboard state or just want to call `Ctrl + V` (`Cmd + V` in Mac) to paste.\n\n```typescript\nimport { paste } from '@xitanggg/node-insert-text';\n\n// Skip custom logics to save clipboard state and write text to clipboard\npaste();\n// Skip custom logics to restore clipboard state\n```\n\n**Build \u0026 Distribution**\n\nIt uses [NAPI-RS](https://github.com/napi-rs/napi-rs) to compile the library into binaries via GitHub actions, package it as a Node-API native addon, and then publish it to npm for distribution and easy use.\n\nOne very nice thing about the NAPI-RS tooling is that the binary has been built, so this package just works after installation, i.e. no need to build it yourself. Also, the binary is selectively installed, meaning installation only installs the binary that your system needs, e.g. windows or Mac, to keep the size small instead of including all binaries at once.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxitanggg%2Fnode-insert-text","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxitanggg%2Fnode-insert-text","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxitanggg%2Fnode-insert-text/lists"}