mod: handle shift and alt key events in adjustKeyEvents()

pull/2/merge
Qingping Hou 12 years ago
parent 1713e2ab0b
commit 6614bbe33d

@ -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

@ -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

@ -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

@ -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

@ -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

@ -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

Loading…
Cancel
Save