1
0
mirror of https://github.com/kepler155c/opus synced 2025-01-19 03:42:51 +00:00

input: dont generate control-char combos

This commit is contained in:
kepler155c@gmail.com 2019-03-24 16:29:49 -04:00
parent 8c50447625
commit 398953af54
2 changed files with 19 additions and 10 deletions

View File

@ -89,8 +89,8 @@ function input:translate(event, code, p1, p2)
end end
elseif event == 'char' then elseif event == 'char' then
if not self.pressed[keys.leftAlt] and if not keyboard.state[keys.leftAlt] and
not self.pressed[keys.rightAlt] then not keyboard.state[keys.rightAlt] then
self.fired = true self.fired = true
return { code = event, ch = code } return { code = event, ch = code }
-- return { code = event, ch = input:toCode(code) } -- return { code = event, ch = input:toCode(code) }

View File

@ -30,6 +30,7 @@ local Util = require('util')
local device = _G.device local device = _G.device
local kernel = _G.kernel local kernel = _G.kernel
local keyboard = _G.device.keyboard local keyboard = _G.device.keyboard
local keys = _G.keys
local mouse = _G.device.mouse local mouse = _G.device.mouse
local os = _G.os local os = _G.os
@ -71,17 +72,25 @@ kernel.hook('peripheral_detach', function(_, eventData)
end end
end) end)
local modifiers = Util.transpose {
keys.leftCtrl, keys.rightCtrl,
keys.leftShift, keys.rightShift,
keys.leftAlt, keys.rightAlt,
}
kernel.hook({ 'key', 'key_up', 'char', 'paste' }, function(event, eventData) kernel.hook({ 'key', 'key_up', 'char', 'paste' }, function(event, eventData)
local code = eventData[1] local code = eventData[1]
-- maintain global keyboard state -- maintain global keyboard state
if event == 'key' then if modifiers[code] then
keyboard.state[code] = true if event == 'key' then
elseif event == 'key_up' then keyboard.state[code] = true
if not keyboard.state[code] then elseif event == 'key_up' then
return true -- ensure key ups are only generated if a key down was sent -- if not keyboard.state[code] then
end -- return true -- ensure key ups are only generated if a key down was sent
-- end
keyboard.state[code] = nil keyboard.state[code] = nil
end
end end
-- and fire hotkeys -- and fire hotkeys
@ -107,8 +116,8 @@ kernel.hook({ 'mouse_click', 'mouse_up', 'mouse_drag' }, function(event, eventDa
end) end)
kernel.hook('kernel_focus', function() kernel.hook('kernel_focus', function()
Util.clear(keyboard.state) --Util.clear(keyboard.state)
Util.clear(mouse.state) --Util.clear(mouse.state)
end) end)
function keyboard.addHotkey(code, fn) function keyboard.addHotkey(code, fn)