I'd like to insert/paste a text in the currently active window and at the focussed element within there, which most likely won't be the app itself (but could be).
I already checked (close to) all clipboard packages / capabilities and it doesn't appear it is possible to initiate a paste event from there. Other solutions for inserting text only seem to be for within the app / mostly for inserting into files.
Tried creating a keyboard even in the rendered process with JS, but this would be limited to the renderer, and I think it should be in the main to even access anything outside the renderer.
Anyone know how to do this / confirm whether or not its even possible?
You could do this using a combination of electron's clipboard module to get the contents of the clipboard and robotjs typeString method to type the string into other applications:
const { clipboard } = require('electron');
const robot = require('robotjs');
const text = clipboard.readText();
robot.typeString(text);
If the text is already in your clipboard, why not just use the paste keyboard command (Ctrl+V)?
robot.keyTap('v', ['control']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With