2021-01-07 19:35 阅读 1

Keyboard keydown event error

I'd like to subscribe to the KeyDown event but it's never triggered as Crafty.trigger("KeyDown", e); iff Crafty.keydown[e.key] !== true and the assignment is made inside the same conditional block.

See https://github.com/craftyjs/Crafty/blob/develop/src/controls.js#L292-L295


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

4条回答 默认 最新

  • weixin_39637589 weixin_39637589 2021-01-07 19:35

    In practice, when does this come up? Can you have two keydown events of the same type without a key up event in between?

    点赞 评论 复制链接分享
  • weixin_39787594 weixin_39787594 2021-01-07 19:35

    Perhaps my experience is related to yours: I tried to listen to key events locally at an entity with Crafty.e("..., Keyboard, ...").bind("KeyDown", function(){}) but it didn't work for me. The fix was to listen to key events globally with Crafty.bind("KeyDown", function(){}) I was pretty newb to crafty back then, so I might have done something wrong.

    点赞 评论 复制链接分享
  • weixin_39637589 weixin_39637589 2021-01-07 19:35

    I'm still a bit confused on what the issue is here. Could someone take a stab at explaining it?

    点赞 评论 复制链接分享
  • weixin_39637589 weixin_39637589 2021-01-07 19:35

    Closing, since I don't see the described bug -- but totally willing to reopen if I'm just not understanding the issue.

    点赞 评论 复制链接分享