steed/stead/kbd.lua

40 lines
830 B
Lua
Raw Normal View History

2010-07-06 11:14:42 +03:00
game.action = stead.hook(game.action, function(f, s, cmd, ...)
if cmd == 'user_kbd' then
2010-07-16 22:56:49 +03:00
local r,v = call(s, 'kbd',
2010-07-06 11:14:42 +03:00
input.key_event.down, input.key_event.key);
if r == nil and v == nil then
return nil, true-- nothing to do
end
return r,v
end
2010-07-14 16:23:24 +03:00
return f(s, cmd, unpack(arg));
2010-07-06 11:14:42 +03:00
end)
input.key = stead.hook(input.key, function(f, s, down, key, ...)
2010-07-14 07:56:46 +03:00
if input._key_hooks[key] then
2010-07-14 07:41:38 +03:00
input.key_event = { key = key, down = down };
return 'user_kbd'
2010-07-06 11:14:42 +03:00
end
return f(s, down, key, unpack(arg))
end)
2010-07-06 12:56:02 +03:00
function hook_keys(...)
local i
for i = 1, stead.table.maxn(arg) do
2010-07-14 07:56:46 +03:00
input._key_hooks[tostring(arg[i])] = true;
end
end
function unhook_keys(...)
local i
for i = 1, stead.table.maxn(arg) do
input._key_hooks[tostring(arg[i])] = nil;
2010-07-06 12:56:02 +03:00
end
end
2010-07-06 11:14:42 +03:00
stead.module_init(function()
2010-07-14 07:56:46 +03:00
input._key_hooks = {}
2010-07-06 11:14:42 +03:00
end)
-- vim:ts=4