mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
input(optimization): replace ev type reflection with table lookup
This commit is contained in:
committed by
Frans de Jonge
parent
597beab616
commit
06562fa582
@@ -62,6 +62,8 @@ an interface to get input events
|
||||
local Input = {
|
||||
-- this depends on keyboard layout and should be overridden:
|
||||
event_map = {},
|
||||
-- adapters are post processing functions that transform a given event to another event
|
||||
event_map_adapter = {},
|
||||
|
||||
group = {
|
||||
Cursor = { "Up", "Down", "Left", "Right" },
|
||||
@@ -266,8 +268,8 @@ function Input:handleKeyBoardEv(ev)
|
||||
return
|
||||
end
|
||||
|
||||
if type(keycode) == "function" then
|
||||
return keycode(ev)
|
||||
if self.event_map_adapter[keycode] then
|
||||
return self.event_map_adapter[keycode](ev)
|
||||
end
|
||||
|
||||
-- take device rotation into account
|
||||
|
||||
@@ -129,20 +129,24 @@ function Kobo:init()
|
||||
self.input = require("device/input"):new{
|
||||
device = self,
|
||||
event_map = {
|
||||
[59] = function(ev)
|
||||
[59] = "SleepCover",
|
||||
[90] = "LightButton",
|
||||
[102] = "Home",
|
||||
[116] = "Power",
|
||||
},
|
||||
event_map_adapter = {
|
||||
SleepCover = function(ev)
|
||||
if self.input:isEvKeyPress(ev) then
|
||||
return "SleepCoverClosed"
|
||||
else
|
||||
return "SleepCoverOpened"
|
||||
end
|
||||
end,
|
||||
[90] = function(ev)
|
||||
LightButton = function(ev)
|
||||
if self.input:isEvKeyRelease(ev) then
|
||||
return "Light"
|
||||
end
|
||||
end,
|
||||
[102] = "Home",
|
||||
[116] = "Power",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user