如何在 jointjs 文件上捕获 keydown 事件?

How to capture a keydown event on jointjs paper?

似乎没有 keydown 与 jointjs 论文相关的事件。我们如何捕获此类事件?

我尝试过的解决方案:

解决方案 1:捕获 div 元素(包含纸张)上的按键。没用。

$('#myholder).on('keydown', (e) => {
    console.log(e.which);
});

方案二:好像有点难。

$(document).on('keydown', (e) => {
if( the previous event fired in 'blank:pointerdown' on paper and no other event is fired after that [which is equivalent to keydown on paper]) {
    console.log(e.which);
}

});

回答这个问题就可以了How to grab keyboard events on an element which doesn't accept focus?

$('#paper')
    .attr('tabindex', 0)
    .on('mouseover', function() {
        this.focus();
    })
    .on('keydown', function(e) {
        console.log(e.which);
    });

在 RappidJS(基于 JointJS 的框架)中还有 ui.Keyboard 插件,它使键盘操作更容易 http://resources.jointjs.com/docs/rappid/v2.1/ui.html#ui.Keyboard