forked from pyrex/chameleonic
Golf keyboard
This commit is contained in:
parent
1be4846698
commit
58bf1d70bf
@ -143,47 +143,37 @@ kbd={}
|
|||||||
add(real_modules,kbd)
|
add(real_modules,kbd)
|
||||||
function kbd:init()
|
function kbd:init()
|
||||||
self.real=btn()
|
self.real=btn()
|
||||||
self.down=0
|
self.state={btn=0}
|
||||||
end
|
end
|
||||||
|
|
||||||
function kbd:update()
|
function kbd:update()
|
||||||
-- figure out what keys are _really_ pressed
|
-- figure out what keys are _really_ pressed
|
||||||
local now_real=btn()
|
local now_real,was_real=btn(),self.real
|
||||||
local was_real=self.real
|
|
||||||
self.real=now_real
|
self.real=now_real
|
||||||
|
|
||||||
-- add keys that are really pressed
|
-- add keys that are really pressed
|
||||||
-- if they weren't really pressed before
|
-- if they weren't really pressed before
|
||||||
-- (they may have been force-
|
-- (they may have been force-
|
||||||
-- released by :release())
|
-- 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 state=self.state
|
||||||
local was_down=self.down
|
local now_down=state.btn&now_real|real_pressed
|
||||||
self.down=now_down
|
local was_down=state.btn
|
||||||
|
|
||||||
-- deduce pressed/released by changes in down
|
-- deduce pressed/released by changes in down
|
||||||
local pressed=(~was_down)&now_down
|
state.btn,state.btnp,state.btnr=
|
||||||
local released=(~now_down)&was_down
|
now_down,
|
||||||
|
~was_down&now_down,
|
||||||
self.pressed=pressed
|
~now_down&was_down
|
||||||
self.released=released
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function kbd:btn(i)
|
for _kbdi in all(split"btn,btnp,btnr") do
|
||||||
return self.down&(1<<i)!=0
|
kbd[_kbdi]=function(self,i,t) return 1<<i&self.state[_kbdi]!=0 end
|
||||||
end
|
|
||||||
|
|
||||||
function kbd:btnp(i)
|
|
||||||
return self.pressed&(1<<i)!=0
|
|
||||||
end
|
|
||||||
|
|
||||||
function kbd:btnr(i)
|
|
||||||
return self.released&(1<<i)!=0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function kbd:release(i)
|
function kbd:release(i)
|
||||||
self.down&=~(1<<i)
|
self.state.btn&=~(1<<i)
|
||||||
end
|
end
|
||||||
|
|
||||||
function tostring(any)
|
function tostring(any)
|
||||||
|
Loading…
Reference in New Issue
Block a user