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

时间:2017-09-14 18:59:05

标签: jointjs

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

我尝试过的解决方案:

解决方案1:捕获div元素(保存纸张)上的keydown。它不起作用。

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

解决方案2:看起来有点困难。

$(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);
}

});

1 个答案:

答案 0 :(得分:3)

这个问题中的答案可以解决问题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