paperjs / paper.js

The Swiss Army Knife of Vector Graphics Scripting – Scriptographer ported to JavaScript and the browser, using HTML5 Canvas. Created by @lehni & @puckey
http://paperjs.org
Other
14.45k stars 1.22k forks source link

Tool keyboard events not firing #1851

Open geoff-harper opened 4 years ago

geoff-harper commented 4 years ago

I'm not seeing keyboard events firing. It's worth noting that I just updated from 0.12.3, where this was working fine, to 0.12.11. The tool's mouse events are working as expected. My code is as follows

My tool class' constructor

this.tool.onMouseDrag = this.drawPath;
this.tool.onMouseDown = this.startPath;
this.tool.onMouseUp = this.finishPath;
this.tool.onKeyUp = this.handleKey;

and the handler

  protected handleKey = (e: paper.KeyEvent) => {
    console.log('e', e)
    switch (e.key) {
      case 'z':
        e.modifiers.shift ? this.redo() : this.undo();
        break;

      default:
        break;
    }
  };

It appears that the canvas element is missing many of the event listeners that it had in 0.12.3, the most relevant listeners being keyup, keypress, etc. The contextmenu and wheel events were added by myself before paper.setup is called

Annotation 2020-08-17 123226

I don't see anything regarding events in the changelogs, please advise if I'm missing something silly. Thanks

dlqqq commented 4 years ago

The event handlers are properties of the Tool object. If you're defining those in some kind of constructor function, I expect that you'd want to bind to this.onKeyUp instead, since this would already refer to the Tool object in that context. Of course, I could be misunderstanding you entirely, so more context would be helpful.

geoff-harper commented 4 years ago

Sorry I should have included more, this.tool is definitely the right instance: protected tool: paper.Tool;. My code is unchanged from 0.12.3 so I don't think it's me but I am not certain

sasensi commented 3 years ago

Hi, could you try to provide us a way to reproduce your issue so that we can look at it closer ?
The best way is to reproduce it in a sketch, please try to extend this one which demonstrate a working keyboard event listener.

geoff-harper commented 3 years ago

That sketch doesn't appear to have the version that it failed on, 0.12.11. My setup is also fairly deeply integrated with other libs so while that could be the cause, the integration also hadn't changed. This also makes it difficult to get into the sketch sandbox. I can take another look at this to see if anything has changed since I've just left the keyboard handlers disabled thus far

sasensi commented 3 years ago

Ok, otherwise, you could also provide us a link to a reproduction repository or another online sandbox with which we can work.