gpt4 book ai didi

javascript - 检测按键文件

转载 作者:行者123 更新时间:2023-12-03 12:30:47 25 4
gpt4 key购买 nike

我正在使用 Electron 设备开发自己的计时器,我想知道如果没有第一个计划中的应用程序,是否有可能检测到按键。例如:我启动应用程序,打开另一个程序,例如discord,当我使用discord时,我可以启动计时器。

最佳答案

从此处的Electron文档中提取:
https://www.electronjs.org/docs/api/global-shortcut

Detect keyboard events when the application does not have keyboardfocus.


The globalShortcut module can register/unregister a global keyboardshortcut with the operating system so that you can customize theoperations for various shortcuts.

Note: The shortcut is global; it will work even if the app does nothave the keyboard focus. You should not use this module until theready event of the app module is emitted.

const { app, globalShortcut } = require('electron')

app.whenReady().then(() => {
// Register a 'CommandOrControl+X' shortcut listener.
const ret = globalShortcut.register('CommandOrControl+X', () => {
console.log('CommandOrControl+X is pressed')
})

if (!ret) {
console.log('registration failed')
}

// Check whether a shortcut is registered.
console.log(globalShortcut.isRegistered('CommandOrControl+X'))
})

app.on('will-quit', () => {
// Unregister a shortcut.
globalShortcut.unregister('CommandOrControl+X')

// Unregister all shortcuts.
globalShortcut.unregisterAll()
})

关于javascript - 检测按键文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63221439/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com