Better-than-nothing key repeat handling.

Mainly aimed at the Forma.
Still fairly terrible, as these things goes ;p.
pull/4500/head
NiLuJe 5 years ago
parent cd4181ba49
commit 81b255cb85

@ -134,6 +134,9 @@ local Input = {
Shift = false,
},
-- repeat state:
repeat_count = 0,
-- touch state:
cur_slot = 0,
MTSlots = {},
@ -388,7 +391,27 @@ function Input:handleKeyBoardEv(ev)
if ev.value == EVENT_VALUE_KEY_PRESS then
return Event:new("KeyPress", key)
elseif ev.value == EVENT_VALUE_KEY_REPEAT then
-- NOTE: We only care about repeat events from the pageturn buttons...
-- And we *definitely* don't want to flood the Event queue with useless SleepCover repeats!
if keycode == "LPgBack"
or keycode == "RPgBack"
or keycode == "LPgFwd"
or keycode == "RPgFwd" then
-- FIXME: Crappy event staggering!
-- The Forma repeats every 80ms after a 400ms delay, and 500ms roughly corresponds to a flashing update,
-- so stuff is usually in sync when you release the key.
-- Obvious downside is that this ends up slower than just mashing the key.
-- FIXME: A better approach would be an onKeyRelease handler that flushes the Event queue...
self.repeat_count = self.repeat_count + 1
if self.repeat_count == 1 then
return Event:new("KeyRepeat", key)
elseif self.repeat_count >= 6 then
self.repeat_count = 0
end
end
elseif ev.value == EVENT_VALUE_KEY_RELEASE then
self.repeat_count = 0
return Event:new("KeyRelease", key)
end
end

@ -228,6 +228,20 @@ function InputContainer:onKeyPress(key)
end
end
-- NOTE: Currently a verbatim copy of onKeyPress ;).
function InputContainer:onKeyRepeat(key)
for name, seq in pairs(self.key_events) do
if not seq.is_inactive then
for _, oneseq in ipairs(seq) do
if key:match(oneseq) then
local eventname = seq.event or name
return self:handleEvent(Event:new(eventname, seq.args, key))
end
end
end
end
end
function InputContainer:onGesture(ev)
for _, tzone in ipairs(self._ordered_touch_zones) do
if tzone.gs_range:match(ev) and tzone.handler(ev) then

Loading…
Cancel
Save