diff --git a/chameleonic.p8 b/chameleonic.p8 index 0cd441e..b2715b2 100644 --- a/chameleonic.p8 +++ b/chameleonic.p8 @@ -117,22 +117,46 @@ end kbd={} add(real_modules,kbd) function kbd:init() - self.prev_real=btn() + self.real=btn() self.down=0 end function kbd:update() - local now=btn() - local pressed=now&~self.prev_real - self.down&=now - self.down|=pressed - self.prev_real=now + -- figure out what keys are _really_ pressed + local now_real=btn() + local was_real=self.real + self.real=now_real + + -- add keys that are really pressed + -- if they weren't really pressed before + -- (they may have been force- + -- released by :release()) + local real_pressed=(~was_real)&now_real + + local now_down=(self.down&now_real)|real_pressed + local was_down=self.down + self.down=now_down + + -- deduce pressed/released by changes in down + local pressed=(~was_down)&now_down + local released=(~now_down)&was_down + + self.pressed=pressed + self.released=released end function kbd:btn(i) return self.down&(1<0) + if (self.rope) self.rope:prevent_highlight(#self.todo>0) _apply(self,self.todo) if self.rope then @@ -686,9 +715,6 @@ function player:update() if self.rope:done() then self.rope=nil - add(self.todo,{}) - add(self.todo,{}) - add(self.todo,{}) end end end