diff --git a/frontend/device/input.lua b/frontend/device/input.lua index 7adcf1d27..ddbead342 100644 --- a/frontend/device/input.lua +++ b/frontend/device/input.lua @@ -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 diff --git a/frontend/device/kobo/device.lua b/frontend/device/kobo/device.lua index f132899b4..32b10b8ff 100644 --- a/frontend/device/kobo/device.lua +++ b/frontend/device/kobo/device.lua @@ -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", } }