mirror of
https://github.com/kepler155c/opus
synced 2025-02-28 23:00:02 +00:00
redo input translation -round 2
This commit is contained in:
parent
2721840596
commit
fe0ca72b8b
@ -13,9 +13,9 @@ local input = {
|
|||||||
pressed = { },
|
pressed = { },
|
||||||
}
|
}
|
||||||
|
|
||||||
function input:toCode(code)
|
function input:toCode(code, ch)
|
||||||
|
|
||||||
local ch = self.ch or keys.getName(code)
|
ch = ch or keys.getName(code)
|
||||||
local result = { }
|
local result = { }
|
||||||
|
|
||||||
if self.pressed[keys.leftCtrl] or self.pressed[keys.rightCtrl] then
|
if self.pressed[keys.leftCtrl] or self.pressed[keys.rightCtrl] then
|
||||||
@ -45,14 +45,17 @@ function input:reset()
|
|||||||
self.pressed = { }
|
self.pressed = { }
|
||||||
self.ch = nil
|
self.ch = nil
|
||||||
self.fired = nil
|
self.fired = nil
|
||||||
|
|
||||||
self.timer = nil
|
self.timer = nil
|
||||||
|
self.mch = nil
|
||||||
|
self.mfired = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function input:translate(event, code, p1, p2)
|
function input:translate(event, code, p1, p2)
|
||||||
if event == 'key' then
|
if event == 'key' then
|
||||||
if p1 then -- key is held down
|
if p1 then -- key is held down
|
||||||
if not modifiers[code] then
|
if not modifiers[code] then
|
||||||
self.fired = input:toCode(code)
|
self.fired = input:toCode(code, self.ch)
|
||||||
return self.fired
|
return self.fired
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -63,66 +66,74 @@ function input:translate(event, code, p1, p2)
|
|||||||
|
|
||||||
elseif event == 'char' then
|
elseif event == 'char' then
|
||||||
self.ch = code
|
self.ch = code
|
||||||
|
-- reset just in case
|
||||||
|
self.pressed[keys.leftCtrl] = nil
|
||||||
|
self.pressed[keys.rightCtrl] = nil
|
||||||
|
|
||||||
elseif event == 'key_up' then
|
elseif event == 'key_up' then
|
||||||
if not self.fired then
|
if not self.fired then
|
||||||
if self.pressed[code] then
|
if self.pressed[code] then
|
||||||
self.fired = input:toCode(code)
|
self.fired = input:toCode(code, self.ch)
|
||||||
self.pressed[code] = nil
|
self.pressed[code] = nil
|
||||||
return self.fired
|
return self.fired
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.pressed[code] = nil
|
self.pressed[code] = nil
|
||||||
|
|
||||||
elseif event == 'mouse_click' then
|
|
||||||
|
|
||||||
local buttons = { 'mouse_click', 'mouse_rightclick' }
|
|
||||||
self.ch = buttons[code]
|
|
||||||
self.fired = nil
|
|
||||||
--self.fired = input:toCode(0)
|
|
||||||
--return self.fired
|
|
||||||
|
|
||||||
elseif event == 'mouse_drag' then
|
|
||||||
self.ch = 'mouse_drag'
|
|
||||||
self.fired = input:toCode(0)
|
|
||||||
return self.fired
|
|
||||||
|
|
||||||
elseif event == 'mouse_up' then
|
|
||||||
if not self.fired then
|
|
||||||
local clock = os.clock()
|
|
||||||
if self.timer and
|
|
||||||
p1 == self.x and p2 == self.y and
|
|
||||||
(clock - self.timer < .5) then
|
|
||||||
|
|
||||||
self.ch = 'mouse_doubleclick'
|
|
||||||
self.timer = nil
|
|
||||||
else
|
|
||||||
self.timer = os.clock()
|
|
||||||
self.x = p1
|
|
||||||
self.y = p2
|
|
||||||
end
|
|
||||||
self.fired = input:toCode(0)
|
|
||||||
else
|
|
||||||
self.ch = 'mouse_up'
|
|
||||||
self.fired = input:toCode(0)
|
|
||||||
end
|
|
||||||
return self.fired
|
|
||||||
|
|
||||||
elseif event == "mouse_scroll" then
|
|
||||||
local directions = {
|
|
||||||
[ -1 ] = 'scrollUp',
|
|
||||||
[ 1 ] = 'scrollDown'
|
|
||||||
}
|
|
||||||
self.ch = directions[code]
|
|
||||||
return input:toCode(0)
|
|
||||||
|
|
||||||
elseif event == 'paste' then
|
elseif event == 'paste' then
|
||||||
self.ch = 'paste'
|
self.ch = 'paste'
|
||||||
self.pressed[keys.leftCtrl] = nil
|
self.pressed[keys.leftCtrl] = nil
|
||||||
self.pressed[keys.rightCtrl] = nil
|
self.pressed[keys.rightCtrl] = nil
|
||||||
self.fired = input:toCode(0)
|
self.fired = input:toCode(0)
|
||||||
return self.fired
|
return self.fired
|
||||||
|
|
||||||
|
elseif event == 'mouse_click' then
|
||||||
|
local buttons = { 'mouse_click', 'mouse_rightclick' }
|
||||||
|
self.mch = buttons[code]
|
||||||
|
self.mfired = nil
|
||||||
|
|
||||||
|
elseif event == 'mouse_drag' then
|
||||||
|
self.mch = 'mouse_drag'
|
||||||
|
self.mfired = input:toCode(0, self.mch)
|
||||||
|
return self.mfired
|
||||||
|
|
||||||
|
elseif event == 'mouse_up' then
|
||||||
|
if not self.mfired then
|
||||||
|
local clock = os.clock()
|
||||||
|
if self.timer and
|
||||||
|
p1 == self.x and p2 == self.y and
|
||||||
|
(clock - self.timer < .5) then
|
||||||
|
|
||||||
|
self.mch = 'mouse_doubleclick'
|
||||||
|
self.timer = nil
|
||||||
|
else
|
||||||
|
self.timer = os.clock()
|
||||||
|
self.x = p1
|
||||||
|
self.y = p2
|
||||||
|
end
|
||||||
|
self.mfired = input:toCode(0, self.mch)
|
||||||
|
else
|
||||||
|
self.mch = 'mouse_up'
|
||||||
|
self.mfired = input:toCode(0, self.mch)
|
||||||
|
end
|
||||||
|
return self.mfired
|
||||||
|
|
||||||
|
elseif event == "mouse_scroll" then
|
||||||
|
local directions = {
|
||||||
|
[ -1 ] = 'scrollUp',
|
||||||
|
[ 1 ] = 'scrollDown'
|
||||||
|
}
|
||||||
|
self.mch = directions[code]
|
||||||
|
return input:toCode(0, self.mch)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function input:test()
|
||||||
|
while true do
|
||||||
|
local ch = self:translate(os.pullEvent())
|
||||||
|
if ch then
|
||||||
|
print('GOT: ' .. ch)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -329,30 +329,6 @@ function multishell.getCount()
|
|||||||
return Util.size(tabs)
|
return Util.size(tabs)
|
||||||
end
|
end
|
||||||
|
|
||||||
function multishell.showMessage(text)
|
|
||||||
parentTerm.setCursorPos(3, 1)
|
|
||||||
parentTerm.setTextColor(_colors.textColor)
|
|
||||||
parentTerm.setBackgroundColor(_colors.backgroundColor)
|
|
||||||
if #text + 3 < w then
|
|
||||||
text = text .. string.rep(' ', w - #text - 3)
|
|
||||||
end
|
|
||||||
parentTerm.write(text)
|
|
||||||
if currentTab then
|
|
||||||
currentTab.window.restoreCursor()
|
|
||||||
end
|
|
||||||
local redrawTimer = os.startTimer(2)
|
|
||||||
|
|
||||||
local redraw
|
|
||||||
function redraw(event, eventData)
|
|
||||||
if eventData[1] == redrawTimer then
|
|
||||||
redrawMenu()
|
|
||||||
multishell.unhook(event, redraw)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
multishell.hook('timer', redraw)
|
|
||||||
end
|
|
||||||
|
|
||||||
function multishell.hook(event, fn)
|
function multishell.hook(event, fn)
|
||||||
if type(event) == 'table' then
|
if type(event) == 'table' then
|
||||||
for _,v in pairs(event) do
|
for _,v in pairs(event) do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user