| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
local base = require 'dokidoki.base' |
| 14 |
|
| 15 |
local key_states = {} |
| 16 |
local old_key_states = {} |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
function key_pressed(key) |
| 21 |
return not not (key_states[key] and not old_key_states[key]) |
| 22 |
end |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
function key_held(key) |
| 27 |
return not not key_states[key] |
| 28 |
end |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
function key_released(key) |
| 33 |
return not not (not key_states[key] and old_key_states[key]) |
| 34 |
end |
| 35 |
|
| 36 |
game.actors.new_generic('key_monitor', function () |
| 37 |
function update_cleanup() |
| 38 |
old_key_states = base.copy(key_states) |
| 39 |
end |
| 40 |
function handle_event(event) |
| 41 |
if event.type == 'key' then |
| 42 |
key_states[event.key] = event.is_down or nil |
| 43 |
end |
| 44 |
end |
| 45 |
end) |