From 69a8ee83bbc3a2e03dad9c59f3e92e76ae126c91 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 27 Mar 2012 19:58:29 +0200 Subject: [PATCH] specify multiple keys for single command #55 This code still doesn't support different modifiers on keys, but I would rather refactor it in small steps first Current changes adds support for Kindle 3 left page keys reported by @houqp in issue #55 --- commands.lua | 11 +++++++++-- unireader.lua | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/commands.lua b/commands.lua index 43dfca87d..a6622ac43 100644 --- a/commands.lua +++ b/commands.lua @@ -62,8 +62,15 @@ Commands = { size = 0 } function Commands:add(keycode,modifier,keydescr,help,func) - local keydef = Keydef:new(keycode,modifier,keydescr) - self:_addImpl(keydef,help,func) + if type(keycode) == "table" then + for i=1,#keycode,1 do + local keydef = Keydef:new(keycode[i],modifier,keydescr) + self:_addImpl(keydef,help,func) + end + else + local keydef = Keydef:new(keycode,modifier,keydescr) + self:_addImpl(keydef,help,func) + end end function Commands:addGroup(keygroup,keys,help,func) for _k,keydef in pairs(keys) do diff --git a/unireader.lua b/unireader.lua index d021cf267..b2cb982a1 100644 --- a/unireader.lua +++ b/unireader.lua @@ -875,12 +875,12 @@ end -- command definitions function UniReader:addAllCommands() self.commands = Commands:new() - self.commands:add(KEY_PGFWD,nil,">", + self.commands:add({KEY_PGFWD,KEY_LPGFWD},nil,">", "next page", function(unireader) unireader:goto(unireader:nextView()) end) - self.commands:add(KEY_PGBCK,nil,"<", + self.commands:add({KEY_PGBCK,KEY_LPGBCK},nil,"<", "previous page", function(unireader) unireader:goto(unireader:prevView())