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
|
2010-07-14 16:23:24 +03:00
|
|
|
return f(s, cmd, unpack(arg));
|
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
|
|
|
|
return f(s, down, key, unpack(arg))
|
|
|
|
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
|
|
|
|
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
|
|
|
-- vim:ts=4
|