1

What I mean by it is like Windows 10's speech dictation - you just launch it while having an active input field in the OS, so you can just speak and this software will insert to the active input field whatever you say.
I tried Googling but didn't find an answer.

Is it possible to get the active input field via Electron?
If so, how?

avi12
  • 2,000
  • 5
  • 24
  • 41

2 Answers2

0

You can use Robotsjs https://github.com/octalmage/robotjs

var robot = require("robotjs");

// Type "Hello World".
robot.typeString("Hello World");
004123
  • 270
  • 1
  • 12
  • Tried installing using `yarn add robotjs`, got [this error](https://i.imgur.com/AQLUUhp.png) – avi12 Mar 10 '19 at 10:54
  • looks like you need to build binaries. see https://github.com/octalmage/robotjs#building – 004123 Mar 10 '19 at 11:11
  • Also I recommend you don't store your node projects within one-drive as I have seen this cause problems. If you need a cloud backup consider using a private github repo. – 004123 Mar 10 '19 at 11:13
  • For serious projects, I'll use private repositories. Otherwise, I'll use OneDrive – avi12 Mar 10 '19 at 11:19
  • I successfully solve this problem thanks to [this reply](https://github.com/felixrieseberg/windows-build-tools/issues/56#issuecomment-308739624) (without `--debug`) – avi12 Mar 10 '19 at 12:34
  • But now [a different problem](https://i.imgur.com/Ubj1KF7.png) occurs whenever I attempt use the function that you've used - for some reason, as this function is being called - the renderer process simply stops – avi12 Mar 10 '19 at 12:36
0

I successfully installed robotjs after following the building section and then executing the code in the reply to the issue in order to first install windows-build-tools.
Then, I executed the code in the 3rd step of this answer (except for tweaking the Electron version so it fits with gRPC, i.e. --target=4.0.3 and tweaking the --abi value to fit my Node version - 10.15.2, so it's --abi=64).

EDIT

At some point, RobotJS caused my application to suddenly exit for some reason.
I sought for another library and found node-key-sender, which not only solved that problem but was also much simpler to install.

avi12
  • 2,000
  • 5
  • 24
  • 41