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

在mac中调用LeftCmd报错 #510

Closed
ittking opened this issue May 15, 2023 · 2 comments
Closed

在mac中调用LeftCmd报错 #510

ittking opened this issue May 15, 2023 · 2 comments

Comments

@ittking
Copy link

ittking commented May 15, 2023

node:36706) UnhandledPromiseRejectionWarning: Error: [nut.js] - Error: Invalid key flag specified.
at libnut. [as keyToggle] (/Users/zhangwei/Public/projects/aitools/node_modules/.pnpm/@nut-tree+libnut-darwin@2.5.1/node_modules/@nut-tree/libnut-darwin/permissionCheck.js:68:96)
at /Users/zhangwei/Public/projects/aitools/node_modules/.pnpm/@nut-tree+nut-js@3.1.1/node_modules/@nut-tree/nut-js/dist/lib/provider/native/libnut-keyboard.class.js:21:28
at new Promise ()
at KeyboardAction.key (/Users/zhangwei/Public/projects/aitools/node_modules/.pnpm/@nut-tree+nut-js@3.1.1/node_modules/@nut-tree/nut-js/dist/lib/provider/native/libnut-keyboard.class.js:16:16)
at /Users/zhangwei/Public/projects/aitools/node_modules/.pnpm/@nut-tree+nut-js@3.1.1/node_modules/@nut-tree/nut-js/dist/lib/provider/native/libnut-keyboard.class.js:63:38
at new Promise ()
at KeyboardAction.pressKey (/Users/zhangwei/Public/projects/aitools/node_modules/.pnpm/@nut-tree+nut-js@3.1.1/node_modules/@nut-tree/nut-js/dist/lib/provider/native/libnut-keyboard.class.js:59:16)
at /Users/zhangwei/Public/projects/aitools/node_modules/.pnpm/@nut-tree+nut-js@3.1.1/node_modules/@nut-tree/nut-js/dist/lib/keyboard.class.js:83:59
(Use Electron --trace-warnings ... to show where the warning was created)

(node:36706) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)

@ittking
Copy link
Author

ittking commented May 15, 2023

我的代码

export async function insertContentToCursor(text) {
  const oldText = clipboard.readText()
  clipboard.writeText(text)
  if (process.platform === 'darwin') {
    await keyboard.pressKey(Key.LeftCmd, Key.V)
    await keyboard.releaseKey(Key.LeftCmd, Key.V)
  } else {
    await keyboard.pressKey(Key.LeftControl, Key.V)
    await keyboard.releaseKey(Key.LeftControl, Key.V)
  }
  clipboard.writeText(oldText)
  return true
}

@s1hofmann
Copy link
Member

Hi @ittking 👋

these keys are not yet supported to be used as modifier keys, see #490

According to your provided snippet you're trying to create a copy/paste workflow.

I'd suggest using Key.LeftSuper. The "Super" key automatically uses the correct key on the respective platform, so you don't have to do this manually.

export async function insertContentToCursor(text) {
  const oldText = clipboard.readText()
  clipboard.writeText(text)
  
  await keyboard.pressKey(Key.LeftSuper, Key.V)
  await keyboard.releaseKey(Key.LeftSuper, Key.V)
  
  clipboard.writeText(oldText)
  return true
}

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

2 participants