mirror of
https://github.com/kepler155c/opus
synced 2024-12-31 19:00:27 +00:00
keyboard handling
This commit is contained in:
parent
398953af54
commit
3f9c219f6b
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user