diff --git a/filechooser.lua b/filechooser.lua index 93a022e64..d2ca88b5c 100644 --- a/filechooser.lua +++ b/filechooser.lua @@ -144,15 +144,12 @@ function FileChooser:choose(ypos, height) fb:refresh(0, 0, ypos, fb.bb:getWidth(), height) pagedirty = false end + local ev = input.waitForEvent() + print("key code:"..ev.code) + ev.code = adjustKeyEvents(ev) if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then - print("key code:"..ev.code) - ev.code = adjustFWKey(ev.code) - if ev.code == KEY_SHIFT then - Keys.shiftmode = true - elseif ev.code == KEY_ALT then - Keys.altmode = true - elseif ev.code == KEY_FW_UP then + if ev.code == KEY_FW_UP then prevItem() elseif ev.code == KEY_FW_DOWN then nextItem() @@ -211,12 +208,6 @@ function FileChooser:choose(ypos, height) elseif ev.code == KEY_BACK then return nil end - elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE - and ev.code == KEY_SHIFT then - Keys.shiftmode = false - elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE - and ev.code == KEY_ALT then - Keys.altmode = false end end end diff --git a/filesearcher.lua b/filesearcher.lua index 9af4b2cbe..25c2a4e2a 100644 --- a/filesearcher.lua +++ b/filesearcher.lua @@ -214,13 +214,9 @@ function FileSearcher:choose(ypos, height, keywords) end local ev = input.waitForEvent() + ev.code = adjustKeyEvents(ev) if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then - ev.code = adjustFWKey(ev.code) - if ev.code == KEY_SHIFT then - Keys.shiftmode = true - elseif ev.code == KEY_ALT then - Keys.altmode = true - elseif ev.code == KEY_FW_UP then + if ev.code == KEY_FW_UP then prevItem() elseif ev.code == KEY_FW_DOWN then nextItem() @@ -276,12 +272,6 @@ function FileSearcher:choose(ypos, height, keywords) elseif ev.code == KEY_BACK then return nil end - elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE - and ev.code == KEY_SHIFT then - Keys.shiftmode = false - elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE - and ev.code == KEY_ALT then - Keys.altmode = false end end end diff --git a/inputbox.lua b/inputbox.lua index 4eab4f95e..ef5cdfc4a 100644 --- a/inputbox.lua +++ b/inputbox.lua @@ -98,14 +98,10 @@ function InputBox:input(ypos, height, title, d_text) end local ev = input.waitForEvent() + ev.code = adjustKeyEvents(ev) if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then - ev.code = adjustFWKey(ev.code) --local secs, usecs = util.gettime() - if ev.code == KEY_SHIFT then - Keys.shiftmode = true - elseif ev.code == KEY_ALT then - Keys.altmode = true - elseif ev.code == KEY_FW_UP then + if ev.code == KEY_FW_UP then elseif ev.code == KEY_FW_DOWN then elseif ev.code == KEY_A then self:addChar("a") @@ -198,12 +194,6 @@ function InputBox:input(ypos, height, title, d_text) --local nsecs, nusecs = util.gettime() --local dur = (nsecs - secs) * 1000000 + nusecs - usecs --print("E: T="..ev.type.." V="..ev.value.." C="..ev.code.." DUR="..dur) - elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE - and ev.code == KEY_SHIFT then - Keys.shiftmode = false - elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE - and ev.code == KEY_ALT then - Keys.altmode = false end end end diff --git a/keys.lua b/keys.lua index a503498e6..3c4c25568 100644 --- a/keys.lua +++ b/keys.lua @@ -201,7 +201,23 @@ function getRotationMode() return mode end -function adjustFWKey(code) +function adjustKeyEvents(ev) + if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then + if ev.code == KEY_SHIFT then + Keys.shiftmode = true + elseif ev.code == KEY_ALT then + Keys.altmode = true + end + elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE then + if ev.code == KEY_SHIFT then + Keys.shiftmode = false + elseif ev.code == KEY_ALT then + Keys.altmode = false + end + end + + -- adjust five way key according to rotation mode + local code = ev.code if getRotationMode() == 0 then return code elseif getRotationMode() == 1 then diff --git a/pdfreader.lua b/pdfreader.lua index 7380c99f6..850637a68 100644 --- a/pdfreader.lua +++ b/pdfreader.lua @@ -45,10 +45,6 @@ PDFReader = { pan_y = 0, pan_margin = 20, - -- keep track of input state: - shiftmode = false, -- shift pressed - altmode = false, -- alt pressed - -- the pdf document: doc = nil, -- the document's setting store: @@ -369,17 +365,13 @@ end function PDFReader:inputloop() while 1 do local ev = input.waitForEvent() + ev.code = adjustKeyEvents(ev) if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then - ev.code = adjustFWKey(ev.code) local secs, usecs = util.gettime() - if ev.code == KEY_SHIFT then - Keys.shiftmode = true - elseif ev.code == KEY_ALT then - Keys.altmode = true - elseif ev.code == KEY_PGFWD or ev.code == KEY_LPGFWD then - if self.shiftmode then + if ev.code == KEY_PGFWD or ev.code == KEY_LPGFWD then + if Keys.shiftmode then self:setglobalzoom(self.globalzoom+0.2) - elseif self.altmode then + elseif Keys.altmode then self:setglobalzoom(self.globalzoom+0.1) else if self.pan_by_page then @@ -389,9 +381,9 @@ function PDFReader:inputloop() self:goto(self.pageno + 1) end elseif ev.code == KEY_PGBCK or ev.code == KEY_LPGBCK then - if self.shiftmode then + if Keys.shiftmode then self:setglobalzoom(self.globalzoom-0.2) - elseif self.altmode then + elseif Keys.altmode then self:setglobalzoom(self.globalzoom-0.1) else if self.pan_by_page then @@ -512,7 +504,7 @@ function PDFReader:inputloop() self.offset_y = self.min_offset_y end elseif ev.code == KEY_FW_PRESS then - if self.shiftmode then + if Keys.shiftmode then if self.pan_by_page then self.offset_x = self.pan_x self.offset_y = self.pan_y @@ -537,11 +529,6 @@ function PDFReader:inputloop() local nsecs, nusecs = util.gettime() local dur = (nsecs - secs) * 1000000 + nusecs - usecs print("E: T="..ev.type.." V="..ev.value.." C="..ev.code.." DUR="..dur) - elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE and ev.code == KEY_SHIFT then - print "shift haha" - Keys.shiftmode = false - elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE and ev.code == KEY_ALT then - Keys.altmode = false end end end diff --git a/selectmenu.lua b/selectmenu.lua index 9057ca9b1..42be614c7 100644 --- a/selectmenu.lua +++ b/selectmenu.lua @@ -167,13 +167,9 @@ function SelectMenu:choose(ypos, height) end local ev = input.waitForEvent() + ev.code = adjustKeyEvents(ev) if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then - ev.code = adjustFWKey(ev.code) - if ev.code == KEY_SHIFT then - Keys.shiftmode = true - elseif ev.code == KEY_ALT then - Keys.altmode = true - elseif ev.code == KEY_FW_UP then + if ev.code == KEY_FW_UP then prevItem() elseif ev.code == KEY_FW_DOWN then nextItem() @@ -205,12 +201,6 @@ function SelectMenu:choose(ypos, height) elseif ev.code == KEY_BACK then return nil end - elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE - and ev.code == KEY_SHIFT then - Keys.shiftmode = false - elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE - and ev.code == KEY_ALT then - Keys.altmode = false end end end