octalmage / robotjs

Node.js Desktop Automation.
http://robotjs.io
MIT License
12.3k stars 949 forks source link

typeString() func it's not work with Electron in macOS #619

Open wallezhang opened 3 years ago

wallezhang commented 3 years ago

Expected Behavior

I register a global shortcut in electron, and in callback call robot.typeString() function. But it seems not work, nothing to be typed. If i call robot.keyTap() function first, and then call robot.typeString() function, that will type a truncate string at first time, and i press the global shortcut again, then it types normal string what i want.

Steps to Reproduce (for bugs)

Here is an example code

    globalShortcut.register('CommandOrControl+Alt+Shift+n', () => {
        console.log('CommandOrControl+Alt+Shift+n is pressed');
        robot.typeString('Hello World');
    });

Above code is not work when i press the shortcut

And if i call robot.keyTap() first

    globalShortcut.register('CommandOrControl+Alt+Shift+n', () => {
        console.log('CommandOrControl+Alt+Shift+n is pressed');
        robot.keyTap('enter');
        robot.typeString('Hello World');
    });

When i press shortcut first, it will type an enter without any string, and then i press shortcut again, it will work.

Your Environment

A1exXxe1A commented 3 years ago

try another key combination, like "Alt+Shift+n"

wallezhang commented 3 years ago

try another key combination, like "Alt+Shift+n"

Yes! It worked!! I found key combination with Command or Control will not work. Is there a conflict?

wallezhang commented 3 years ago

BTW, robot.keyTap() function is work as expect whatever key combination i use.