Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keyboard type function doesn't type entire string at once #460

Closed
himat opened this issue Dec 26, 2022 · 8 comments
Closed

keyboard type function doesn't type entire string at once #460

himat opened this issue Dec 26, 2022 · 8 comments

Comments

@himat
Copy link

himat commented Dec 26, 2022

It seems the nut.js keyboard type function doesn't type the entire string at once like the robotjs one did?
This is pretty inconvenient when you want to enter in an entire piece of text at once.

If you compare

keyboard.type('hi there');

vs

robot.typeString('hi there');

The first one types char by char which takes a while, whereas the second inputs the entire string instantly into whatever text box you're in.

I saw that I can configure the delay for nut
keyboard.config.autoDelayMs = 50;
But that parameter is not working well. At 100, it types correctly, but if I lower it to 50, I saw the first character was missing, and if I lowered it to 10, many characters were not typed.

Is there a workaround for this that makes the typing equivalent to the robotjs way?

@s1hofmann
Copy link
Member

s1hofmann commented Dec 26, 2022

Hi @himat 👋

Just to make sure, which OS are you on?

A simple workaround to this problem would be to use clipboard.copy('your string');, followed by pressing the paste shortcut inside the textbox, e.g.

clipboard.copy("you string");
keyboard.pressKey(Key.LeftSuper, Key.V); // macOS
keyboard.releaseKey(Key.LeftSuper, Key.V); // macOS

// keyboard.pressKey(Key.LeftControl, Key.V); // For Windows and Linux
// keyboard.releaseKey(Key.LeftControl, Key.V); // For Windows and Linux

Simon

@himat
Copy link
Author

himat commented Dec 26, 2022

Thanks Simon

Yeah that would work for me for now. Although I don't like the idea of replacing what's in the user's clipboard though every time. So I think it would be more sustainable to be able to directly paste the entire text just like how pasting from the clipboard does it.

@s1hofmann
Copy link
Member

Hi @himat 👋

modifying the clipboard content is not ideal, yes, but if you really want to have instant pasting, this is the only way to go.
Lowering the keyboard delay to 0 will still type one character after another, I'm pretty sure this is no different in robot.js.

I'll have a look at the behaviour you described, though.

@himat
Copy link
Author

himat commented Dec 27, 2022

@s1hofmann yeah I think you're right.

But then is there a way to do what the clipboard pasting does of entering in an entire piece of text at once that can be replicated without saving to the clipboard?

@zaneschepke
Copy link

I have also noticed this same behavior. If I had delay set to 20 ms it skipped the first three characters of what I was trying to type.

This is on Windows 11.

@ex-tag
Copy link

ex-tag commented Jul 16, 2023

On MacOS 13

I have not noticed any skipping of letters when setting the delay to 0

const { keyboard } = require("@nut-tree/nut-js");

keyboard.config.autoDelayMs = 0;
(async () => {
  await keyboard.type("my string");
})();

And I can paste from the clipboard

const { clipboard, keyboard, Key } = require("@nut-tree/nut-js");

(async () => {
  await clipboard.setContent("my string");
  await keyboard.pressKey(Key.LeftSuper, Key.V);
  await keyboard.releaseKey(Key.LeftSuper, Key.V);
})();

@Justiniscoding
Copy link

If you are planning to use the clipboard method to type the string all at once, you can store the initial value of the clipboard in a variable and then set it back to the initial value after your script is done executing

@s1hofmann
Copy link
Member

Closed due to inactivity, feel free to re-open on updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants