keyboard handling

This commit is contained in:
kepler155c@gmail.com 2019-03-24 17:00:42 -04:00
parent 398953af54
commit 3f9c219f6b
2 changed files with 9 additions and 11 deletions

View File

@ -39,11 +39,11 @@ function input:toCode(ch, code)
-- the key-up event for alt keys is not generated if the minecraft
-- window loses focus
--
-- if keyboard.state[keys.leftAlt] or keyboard.state[keys.rightAlt] or
-- code == keys.leftAlt or code == keys.rightAlt then
-- table.insert(result, 'alt')
-- end
if keyboard.state[keys.leftAlt] or keyboard.state[keys.rightAlt] or
code == keys.leftAlt or code == keys.rightAlt then
table.insert(result, 'alt')
end
if keyboard.state[keys.leftShift] or keyboard.state[keys.rightShift] or
code == keys.leftShift or code == keys.rightShift then

View File

@ -75,21 +75,18 @@ end)
local modifiers = Util.transpose {
keys.leftCtrl, keys.rightCtrl,
keys.leftShift, keys.rightShift,
keys.leftAlt, keys.rightAlt,
--keys.leftAlt, keys.rightAlt,
}
kernel.hook({ 'key', 'key_up', 'char', 'paste' }, function(event, eventData)
local code = eventData[1]
-- maintain global keyboard state
-- maintain global keyboard modifier state
if modifiers[code] then
if event == 'key' then
keyboard.state[code] = true
elseif event == 'key_up' then
-- if not keyboard.state[code] then
-- 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
@ -98,6 +95,7 @@ kernel.hook({ 'key', 'key_up', 'char', 'paste' }, function(event, eventData)
if hotkey and keyboard.hotkeys[hotkey.code] then
keyboard.hotkeys[hotkey.code](event, eventData)
return true
end
end)