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

Issue with keyboard.type in to Spotlight on MacOS (Catalina) #152

Closed
1 of 3 tasks
jackroberts-gh opened this issue Jun 2, 2020 · 3 comments · Fixed by #361
Closed
1 of 3 tasks

Issue with keyboard.type in to Spotlight on MacOS (Catalina) #152

jackroberts-gh opened this issue Jun 2, 2020 · 3 comments · Fixed by #361
Labels
bug Something isn't working
Milestone

Comments

@jackroberts-gh
Copy link

jackroberts-gh commented Jun 2, 2020

Version
@nut-tree/nut-js": "^1.4.1"

Short overview

Following an example on trailmix under "type" (https://github.com/nut-tree/trailmix/tree/master/packages/keyboard-test) I try to open Spotlight and then type. However, it seems that when trying to do this with keyboard.type("string") it very rarely works, or it types part of the string, etc.

Issue occurs on

  • Virtual machine
  • Docker container
  • Dev/Host system

Detailed error description

Following an example on trailmix under "type" (https://github.com/nut-tree/trailmix/tree/master/packages/keyboard-test) I try to open Spotlight and then type. However, it seems that when trying to do this with keyboard.type("string") it very rarely works, or it types part of the string, etc.

Using "keyboard.type(Key.S, Key.T.. etc)" seems to work no problem, so it seems to be an issue with passing in a String to the keyboard.type function.

Steps to reproduce error

(async () => {
    const { mouse, keyboard, Key, screen, right, down, left, up } = require("@nut-tree/nut-js");

    keyboard.config.autoDelayMs = 250;

    // this takes in a string and types it out using the Key. method rather than by string
    const hackFix = async (string) => {
         string.split("").forEach(async (char) => {
             const character = char.toUpperCase()
             await keyboard.type(Key[character])
        });
    }

    try {
        await keyboard.type(Key.LeftSuper, Key.Space); // bring up spotlight

        await keyboard.type("calculator"); // this doesn't work 
        await hackFix("CALCULATOR") // this works

        await keyboard.pressKey(Key.Enter);
        await keyboard.releaseKey(Key.Enter);
    } catch (e) {
        console.log(e)
    }

})();

Additional content
N/A

@jackroberts-gh
Copy link
Author

jackroberts-gh commented Jun 2, 2020

I'm aware the hackFix async function doesn't actually await but it seems to make no difference for the purposes of this, whether I do it this way or do lots of separate "await keyboard.type(Key.C) etc" commands to type out calculator.

In my limited experience with this library, it isn't just typing in to Spotlight that causes this. It sees to type OK in to the terminal, but i'm currently able to type in to a virtual machine in the background using "keyboard.type(Key.C)" but "keyboard.type("C")" doesnt work.

@s1hofmann
Copy link
Member

Hi @jzr1991,

both keyboard.type(Key.C) and keyboard.type("C") cause the same native keytap event.
Nonetheless you're right. When passing a string to type, input to Spotlight might get lost.

I'll take a closer look, thanks for reporting!

Best regards

Simon

@s1hofmann s1hofmann added the bug Something isn't working label Jun 3, 2020
@s1hofmann s1hofmann added this to the TipTap milestone Jan 20, 2022
s1hofmann added a commit to nut-tree/libnut-core that referenced this issue Jan 21, 2022
s1hofmann added a commit to nut-tree/libnut-core that referenced this issue Jan 21, 2022
…GHIDEventTap consistently to not lose input (#99)
@s1hofmann s1hofmann linked a pull request Jan 21, 2022 that will close this issue
@s1hofmann
Copy link
Member

Closed by #361

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants