steed/stead/kbd.lua

47 lines
980 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-29 11:57:00 +03:00
local r,v;
if here().kbd then
r,v = call(here(), 'kbd',
2010-07-06 11:14:42 +03:00
input.key_event.down, input.key_event.key);
2010-07-29 11:57:00 +03:00
elseif s.kbd then
r,v = call(s, 'kbd',
input.key_event.down, input.key_event.key);
end
2010-07-06 11:14:42 +03:00
if r == nil and v == nil then
return nil, true-- nothing to do
end
return r,v
end
2011-02-23 12:11:27 +02:00
return f(s, cmd, ...);
2010-07-06 11:14:42 +03:00
end)
2010-07-22 13:39:48 +03:00
stead.module_init(function()
input.key = stead.hook(input.key, function(f, s, down, key, ...)
if input._key_hooks[key] then
input.key_event = { key = key, down = down };
return 'user_kbd'
end
2011-02-23 12:11:27 +02:00
return f(s, down, key, ...)
2010-07-22 13:39:48 +03:00
end)
input._key_hooks = {}
2010-07-06 11:14:42 +03:00
end)
2010-07-06 12:56:02 +03:00
function hook_keys(...)
local i
2011-02-23 12:11:27 +02:00
local a = {...};
for i = 1, stead.table.maxn(a) do
input._key_hooks[tostring(a[i])] = true;
2010-07-14 07:56:46 +03:00
end
end
function unhook_keys(...)
local i
2011-02-23 12:11:27 +02:00
local a = {...};
for i = 1, stead.table.maxn(a) do
input._key_hooks[tostring(a[i])] = nil;
2010-07-06 12:56:02 +03:00
end
end
2010-07-06 11:14:42 +03:00
-- vim:ts=4