2

I have tried to register global keyboard shortcut using Electron's global-shortcut module, as per the documentation page. (https://github.com/atom/electron/blob/master/docs/api/global-shortcut.md)

However, I received the following error in my console when I run electron:

[20097:0608/181936:FATAL:global_shortcut_listener_x11.cc(49)] Check failed: BrowserThread::CurrentlyOn(BrowserThread::UI). 

I am running Electron on Ubuntu 14.04 LTS. I would like to ask if this error is platform-specific. Are there any steps I missed out from the documentation page? If there isn't, is there any way to get around this error? Thanks.

4

1 回答 1

5

Your application should be ready before you register your shortcuts. Here is an example:

var app = require('app');  
var globalShortcut = require('global-shortcut');

// Your app must be ready before the registration
app.on('ready', function() {
    console.log('Your app is ready!');

    // You can now register your shortcuts
    globalShortcut.register('ctrl+alt+j', function() {
        console.log('You fired ctrl+alt+j !!!');
    });
});
于 2015-06-10T17:45:01.990 回答