diff --git a/BizHawk.MultiClient/LuaImplementation.cs b/BizHawk.MultiClient/LuaImplementation.cs index a40c6a55b3..b34bb5c941 100644 --- a/BizHawk.MultiClient/LuaImplementation.cs +++ b/BizHawk.MultiClient/LuaImplementation.cs @@ -90,6 +90,13 @@ namespace BizHawk.MultiClient LuaLibraryList += "movie." + MovieFunctions[i] + "\n"; } + lua.NewTable("input"); + for (int i = 0; i < InputFunctions.Length; i++) + { + lua.RegisterFunction("input." + InputFunctions[i], this, this.GetType().GetMethod("input_" + InputFunctions[i])); + LuaLibraryList += "input." + InputFunctions[i] + "\n"; + } + lua.NewTable("joypad"); for (int i = 0; i < JoypadFunctions.Length; i++) { @@ -291,6 +298,10 @@ namespace BizHawk.MultiClient //"rerecordcounting", }; + public static string[] InputFunctions = new string[] { + "get", + }; + public static string[] JoypadFunctions = new string[] { "set", "get", @@ -1093,6 +1104,26 @@ namespace BizHawk.MultiClient Global.MainForm.SetReadOnly(false); } + //---------------------------------------------------- + //Input library + //---------------------------------------------------- + public LuaTable input_get() + { + LuaTable keys = new LuaTable(1, lua); + string[] keystrings = Global.MainForm.lastKeyboard.Split(' '); + + foreach (string keypress in keystrings) + { + if (keypress.Contains("Press:")) + { + string key = keypress.Replace("Press:", ""); + keys[key] = key; + } + } + + return keys; + } + //---------------------------------------------------- //Joypad library //---------------------------------------------------- diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs index 29384091e7..695d8702ca 100644 --- a/BizHawk.MultiClient/MainForm.cs +++ b/BizHawk.MultiClient/MainForm.cs @@ -1334,20 +1334,24 @@ namespace BizHawk.MultiClient } } + public string lastKeyboard = ""; + public void ProcessInput() { for (; ; ) { //loop through all available events var ie = Input.Instance.DequeueEvent(); - if (ie == null) break; + if (ie == null) { break; } //useful debugging: //Console.WriteLine(ie); //TODO - wonder what happens if we pop up something interactive as a response to one of these hotkeys? may need to purge further processing - //look for client control bindings for this key + lastKeyboard += " " + ie.ToString(); + + //look for client cntrol bindings for this key var triggers = Global.ClientControls.SearchBindings(ie.LogicalButton.ToString()); if (triggers.Count == 0) { @@ -1423,7 +1427,7 @@ namespace BizHawk.MultiClient case "Quick Save State": if (!IsNullEmulator()) - SaveState("QuickSave" + Global.Config.SaveSlot.ToString()); + SaveState("QuickSave" + Global.Config.SaveSlot.ToString()); break; case "Quick Load State": @@ -1469,21 +1473,11 @@ namespace BizHawk.MultiClient case "LoadSlot7": if (!IsNullEmulator()) LoadState("QuickSave7"); break; case "LoadSlot8": if (!IsNullEmulator()) LoadState("QuickSave8"); break; case "LoadSlot9": if (!IsNullEmulator()) LoadState("QuickSave9"); break; - case "SelectSlot0": - OnSelectSlot(0); - break; - case "SelectSlot1": - OnSelectSlot(1); - break; - case "SelectSlot2": - OnSelectSlot(2); - break; - case "SelectSlot3": - OnSelectSlot(3); - break; - case "SelectSlot4": - OnSelectSlot(4); - break; + case "SelectSlot0": OnSelectSlot(0); break; + case "SelectSlot1": OnSelectSlot(1); break; + case "SelectSlot2": OnSelectSlot(2); break; + case "SelectSlot3": OnSelectSlot(3); break; + case "SelectSlot4": OnSelectSlot(4); break; case "SelectSlot5": OnSelectSlot(5); break; case "SelectSlot6": OnSelectSlot(6); break; case "SelectSlot7": OnSelectSlot(7); break; @@ -1774,7 +1768,7 @@ namespace BizHawk.MultiClient Global.Emulator.FrameAdvance(!throttle.skipnextframe); MemoryPulse.Pulse(); //======================================= - + lastKeyboard = ""; if (CurrAviWriter != null) { //TODO - this will stray over time! have AviWriter keep an accumulation!