2013-11-26 01:21:24 +00:00
|
|
|
|
using System.Linq;
|
2013-10-28 19:13:01 +00:00
|
|
|
|
using System.Windows.Forms;
|
2013-10-31 23:55:17 +00:00
|
|
|
|
|
|
|
|
|
using BizHawk.Client.Common;
|
2014-01-26 13:30:45 +00:00
|
|
|
|
using LuaInterface;
|
2013-10-28 19:13:01 +00:00
|
|
|
|
|
2013-11-03 03:54:37 +00:00
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
2013-10-31 13:07:42 +00:00
|
|
|
|
public class InputLuaLibrary : LuaLibraryBase
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
2013-10-31 13:07:42 +00:00
|
|
|
|
public InputLuaLibrary(Lua lua)
|
|
|
|
|
{
|
2014-05-20 20:34:51 +00:00
|
|
|
|
Lua = lua;
|
2013-10-31 13:07:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Name { get { return "input"; } }
|
|
|
|
|
|
2014-01-26 13:30:45 +00:00
|
|
|
|
[LuaMethodAttributes(
|
|
|
|
|
"get",
|
2014-01-26 18:36:27 +00:00
|
|
|
|
"Returns a lua table of all the buttons the user is currently pressing on their keyboard and gamepads"
|
2014-01-26 13:30:45 +00:00
|
|
|
|
)]
|
|
|
|
|
public LuaTable Get()
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
2014-05-20 20:34:51 +00:00
|
|
|
|
var buttons = Lua.NewTable();
|
2013-12-24 21:37:51 +00:00
|
|
|
|
foreach (var kvp in Global.ControllerInputCoalescer.BoolButtons().Where(kvp => kvp.Value))
|
2013-11-26 01:21:24 +00:00
|
|
|
|
{
|
|
|
|
|
buttons[kvp.Key] = true;
|
|
|
|
|
}
|
2014-01-26 13:30:45 +00:00
|
|
|
|
|
2013-10-28 19:13:01 +00:00
|
|
|
|
return buttons;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-26 13:30:45 +00:00
|
|
|
|
[LuaMethodAttributes(
|
|
|
|
|
"getmouse",
|
2014-01-26 18:36:27 +00:00
|
|
|
|
"Returns a lua table of the mouse X/Y coordinates and button states. Table returns the values X, Y, Left, Middle, Right, XButton1, XButton2"
|
2014-01-26 13:30:45 +00:00
|
|
|
|
)]
|
|
|
|
|
public LuaTable GetMouse()
|
2013-10-28 19:13:01 +00:00
|
|
|
|
{
|
2014-05-20 20:34:51 +00:00
|
|
|
|
var buttons = Lua.NewTable();
|
2014-04-15 21:46:18 +00:00
|
|
|
|
//TODO - need to specify whether in "emu" or "native" coordinate space.
|
|
|
|
|
var p = GlobalWin.DisplayManager.UntransformPoint(Control.MousePosition);
|
2013-10-28 19:13:01 +00:00
|
|
|
|
buttons["X"] = p.X;
|
|
|
|
|
buttons["Y"] = p.Y;
|
|
|
|
|
buttons[MouseButtons.Left.ToString()] = (Control.MouseButtons & MouseButtons.Left) != 0;
|
|
|
|
|
buttons[MouseButtons.Middle.ToString()] = (Control.MouseButtons & MouseButtons.Middle) != 0;
|
|
|
|
|
buttons[MouseButtons.Right.ToString()] = (Control.MouseButtons & MouseButtons.Right) != 0;
|
|
|
|
|
buttons[MouseButtons.XButton1.ToString()] = (Control.MouseButtons & MouseButtons.XButton1) != 0;
|
|
|
|
|
buttons[MouseButtons.XButton2.ToString()] = (Control.MouseButtons & MouseButtons.XButton2) != 0;
|
|
|
|
|
return buttons;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|