BizHawk/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.Input.cs

40 lines
1.2 KiB
C#
Raw Normal View History

using System;
2013-10-31 23:55:17 +00:00
using NLua;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
public sealed class InputLuaLibrary : DelegatingLuaLibraryEmu
{
public InputLuaLibrary(Lua lua)
: base(lua) { }
public InputLuaLibrary(Lua lua, Action<string> logOutputCallback)
: base(lua, logOutputCallback) { }
2017-05-19 14:47:18 +00:00
public override string Name => "input";
[LuaMethodExample("local nlinpget = input.get( );")]
[LuaMethod("get", "Returns a lua table of all the buttons the user is currently pressing on their keyboard and gamepads\nAll buttons that are pressed have their key values set to true; all others remain nil.")]
public LuaTable Get()
{
var result = APIs.Input.Get();
var table = Lua.NewTable();
foreach (var kvp in result) table[kvp.Key] = kvp.Value;
return table;
}
[LuaMethodExample("local nlinpget = input.getmouse( );")]
[LuaMethod("getmouse", "Returns a lua table of the mouse X/Y coordinates and button states. Table keys are X, Y, Left, Middle, Right, XButton1, XButton2, Wheel.")]
public LuaTable GetMouse()
{
var result = APIs.Input.GetMouse();
var table = Lua.NewTable();
foreach (var kvp in result) table[kvp.Key] = kvp.Value;
return table;
}
}
}