問題描述
我想知道是否有辦法使用 Atom Electron 創建一個應用程序,當用戶專注于/不專注于我的應用程序時,該應用程序運行并獲取我的鍵盤事件.
I would like to know if there is a way to make an application with Atom Electron that runs and gets my keyboard events when the user is/isn't focused on my app.
例如,如果他在 Chrome 上寫了一些東西,我的應用程序將存儲他按下的所有鍵.我搜索了一下,但沒有找到解決我問題的方法.
For example if he is on Chrome and writes something, my app will store all the keys that he pressed. I searched a little but didn't find something that solves my problem.
推薦答案
與您正在尋找的最接近的是全局快捷方式:https://github.com/electron/electron/blob/master/docs/api/global-shortcut.md.雖然您在核心 Electron 中沒有任何東西來支持開箱即用地捕獲所有鍵盤事件,但幸運的是 node.js 可以通過 本地節點插件.
The closest thing there is to what you're looking for is global shortcuts: https://github.com/electron/electron/blob/master/docs/api/global-shortcut.md. While you don't have anything in core Electron to support capturing all keyboard events out of the box, luckily node.js is pretty extensible with native node addons.
這篇關于即使應用沒有聚焦,Atom Electron 也會捕獲所有鍵盤事件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!