From 58bf1d70bff18f8f3e3b29ee0c944dabd382a6d1 Mon Sep 17 00:00:00 2001 From: Nyeogmi Date: Thu, 22 Dec 2022 18:49:03 -0800 Subject: [PATCH] Golf keyboard --- chameleonic.p8 | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/chameleonic.p8 b/chameleonic.p8 index 512d466..00bb6a9 100644 --- a/chameleonic.p8 +++ b/chameleonic.p8 @@ -143,47 +143,37 @@ kbd={} add(real_modules,kbd) function kbd:init() self.real=btn() - self.down=0 + self.state={btn=0} end function kbd:update() -- figure out what keys are _really_ pressed - local now_real=btn() - local was_real=self.real + local now_real,was_real=btn(),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 real_pressed=~was_real&now_real - local now_down=(self.down&now_real)|real_pressed - local was_down=self.down - self.down=now_down + local state=self.state + local now_down=state.btn&now_real|real_pressed + local was_down=state.btn -- 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 + state.btn,state.btnp,state.btnr= + now_down, + ~was_down&now_down, + ~now_down&was_down end -function kbd:btn(i) - return self.down&(1<