InputWidget overhaul to use the new GetPressedKeys() function. InputWidget no longer wipes all mappings. In autotab mode it replaces the first key mapping instead of all. There is now a max number of bindings of 4 (but changeable). Still has some quirks to work out like Alt+F4 no longer closes the dialog, and TAB has weird behavior. Also, need to implement non-autotab handling. Reworked Hotkey config to use this inputwidget, but not inputconfig yet

This commit is contained in:
andres.delikat 2011-07-09 16:12:56 +00:00
parent 16e332a72d
commit 6949a8dd59
3 changed files with 661 additions and 755 deletions

File diff suppressed because it is too large Load Diff

View File

@ -14,80 +14,80 @@ namespace BizHawk.MultiClient.tools
public HotkeyWindow()
{
InitializeComponent();
IDW_FRAMEADVANCE.Text = Global.Config.FrameAdvanceBinding;
IDW_PAUSE.Text = Global.Config.EmulatorPauseBinding;
IDW_HARDRESET.Text = Global.Config.HardResetBinding;
IDW_REWIND.Text = Global.Config.RewindBinding;
IDW_UNTHROTTLE.Text = Global.Config.TurboBinding;
IDW_FASTFORWARD.Text = Global.Config.FastForwardBinding;
IDW_SCREENSHOT.Text = Global.Config.ScreenshotBinding;
IDW_FULLSCREEN.Text = Global.Config.ToggleFullscreenBinding;
IDW_FRAMEADVANCE.SetBindings(Global.Config.FrameAdvanceBinding);
IDW_PAUSE.SetBindings(Global.Config.EmulatorPauseBinding);
IDW_HARDRESET.SetBindings(Global.Config.HardResetBinding);
IDW_REWIND.SetBindings(Global.Config.RewindBinding);
IDW_UNTHROTTLE.SetBindings(Global.Config.TurboBinding);
IDW_FASTFORWARD.SetBindings(Global.Config.FastForwardBinding);
IDW_SCREENSHOT.SetBindings(Global.Config.ScreenshotBinding);
IDW_FULLSCREEN.SetBindings(Global.Config.ToggleFullscreenBinding);
IDW_QuickSave.Text = Global.Config.QuickSave;
IDW_QuickLoad.Text = Global.Config.QuickLoad;
IDW_QuickSave.SetBindings(Global.Config.QuickSave);
IDW_QuickLoad.SetBindings(Global.Config.QuickLoad);
//Save States
IDW_SS0.Text = Global.Config.SaveSlot0;
IDW_SS1.Text = Global.Config.SaveSlot1;
IDW_SS2.Text = Global.Config.SaveSlot2;
IDW_SS3.Text = Global.Config.SaveSlot3;
IDW_SS4.Text = Global.Config.SaveSlot4;
IDW_SS5.Text = Global.Config.SaveSlot5;
IDW_SS6.Text = Global.Config.SaveSlot6;
IDW_SS7.Text = Global.Config.SaveSlot7;
IDW_SS8.Text = Global.Config.SaveSlot8;
IDW_SS9.Text = Global.Config.SaveSlot9;
IDW_SS0.SetBindings(Global.Config.SaveSlot0);
IDW_SS1.SetBindings(Global.Config.SaveSlot1);
IDW_SS2.SetBindings(Global.Config.SaveSlot2);
IDW_SS3.SetBindings(Global.Config.SaveSlot3);
IDW_SS4.SetBindings(Global.Config.SaveSlot4);
IDW_SS5.SetBindings(Global.Config.SaveSlot5);
IDW_SS6.SetBindings(Global.Config.SaveSlot6);
IDW_SS7.SetBindings(Global.Config.SaveSlot7);
IDW_SS8.SetBindings(Global.Config.SaveSlot8);
IDW_SS9.SetBindings(Global.Config.SaveSlot9);
//Load States
IDW_LS0.Text = Global.Config.LoadSlot0;
IDW_LS1.Text = Global.Config.LoadSlot1;
IDW_LS2.Text = Global.Config.LoadSlot2;
IDW_LS3.Text = Global.Config.LoadSlot3;
IDW_LS4.Text = Global.Config.LoadSlot4;
IDW_LS5.Text = Global.Config.LoadSlot5;
IDW_LS6.Text = Global.Config.LoadSlot6;
IDW_LS7.Text = Global.Config.LoadSlot7;
IDW_LS8.Text = Global.Config.LoadSlot8;
IDW_LS9.Text = Global.Config.LoadSlot9;
IDW_LS0.SetBindings(Global.Config.LoadSlot0);
IDW_LS1.SetBindings(Global.Config.LoadSlot1);
IDW_LS2.SetBindings(Global.Config.LoadSlot2);
IDW_LS3.SetBindings(Global.Config.LoadSlot3);
IDW_LS4.SetBindings(Global.Config.LoadSlot4);
IDW_LS5.SetBindings(Global.Config.LoadSlot5);
IDW_LS6.SetBindings(Global.Config.LoadSlot6);
IDW_LS7.SetBindings(Global.Config.LoadSlot7);
IDW_LS8.SetBindings(Global.Config.LoadSlot8);
IDW_LS9.SetBindings(Global.Config.LoadSlot9);
//Select States
IDW_ST0.Text = Global.Config.SelectSlot0;
IDW_ST1.Text = Global.Config.SelectSlot1;
IDW_ST2.Text = Global.Config.SelectSlot2;
IDW_ST3.Text = Global.Config.SelectSlot3;
IDW_ST4.Text = Global.Config.SelectSlot4;
IDW_ST5.Text = Global.Config.SelectSlot5;
IDW_ST6.Text = Global.Config.SelectSlot6;
IDW_ST7.Text = Global.Config.SelectSlot7;
IDW_ST8.Text = Global.Config.SelectSlot8;
IDW_ST9.Text = Global.Config.SelectSlot9;
IDW_TOOLBOX.Text = Global.Config.ToolBox;
IDW_SAVENAMEDSTATE.Text = Global.Config.SaveNamedState;
IDW_LOADNAMEDSTATE.Text = Global.Config.LoadNamedState;
IDW_NEXTSLOT.Text = Global.Config.NextSlot;
IDW_PREVIOUSSLOT.Text = Global.Config.PreviousSlot;
IDW_RamWatch.Text = Global.Config.RamWatch;
IDW_RamSearch.Text = Global.Config.RamSearch;
IDW_RamPoke.Text = Global.Config.RamPoke;
IDW_HexEditor.Text = Global.Config.HexEditor;
IDW_LuaConsole.Text = Global.Config.LuaConsole;
IDW_Cheats.Text = Global.Config.Cheats;
IDW_OpenROM.Text = Global.Config.OpenROM;
IDW_CloseROM.Text = Global.Config.CloseROM;
IDW_DisplayFPS.Text = Global.Config.FPSBinding;
IDW_FrameCounter.Text = Global.Config.FrameCounterBinding;
IDW_LagCounter.Text = Global.Config.LagCounterBinding;
IDW_InputDisplay.Text = Global.Config.InputDisplayBinding;
IDW_TOGGLEREADONLY.Text = Global.Config.ReadOnlyToggleBinding;
IDW_PLAYMOVIE.Text = Global.Config.PlayMovieBinding;
IDW_RECORDMOVIE.Text = Global.Config.RecordMovieBinding;
IDW_STOPMOVIE.Text = Global.Config.StopMovieBinding;
IDW_PLAYBEGINNING.Text = Global.Config.PlayBeginningBinding;
IDW_VOLUP.Text = Global.Config.VolUpBinding;
IDW_VOLDOWN.Text = Global.Config.VolDownBinding;
IDW_TOGGLEMTRACK.Text = Global.Config.ToggleMultiTrack;
IDW_SELECTNONE.Text = Global.Config.MTRecordNone;
IDW_MTSELECTALL.Text = Global.Config.MTRecordAll;
IDW_MTINCPLAYER.Text = Global.Config.MTIncrementPlayer;
IDW_MTDECPLAYER.Text = Global.Config.MTDecrementPlayer;
IDW_RESET.Text = Global.Config.SoftResetBinding;
IDW_ST0.SetBindings(Global.Config.SelectSlot0);
IDW_ST1.SetBindings(Global.Config.SelectSlot1);
IDW_ST2.SetBindings(Global.Config.SelectSlot2);
IDW_ST3.SetBindings(Global.Config.SelectSlot3);
IDW_ST4.SetBindings(Global.Config.SelectSlot4);
IDW_ST5.SetBindings(Global.Config.SelectSlot5);
IDW_ST6.SetBindings(Global.Config.SelectSlot6);
IDW_ST7.SetBindings(Global.Config.SelectSlot7);
IDW_ST8.SetBindings(Global.Config.SelectSlot8);
IDW_ST9.SetBindings(Global.Config.SelectSlot9);
IDW_TOOLBOX.SetBindings(Global.Config.ToolBox);
IDW_SAVENAMEDSTATE.SetBindings(Global.Config.SaveNamedState);
IDW_LOADNAMEDSTATE.SetBindings(Global.Config.LoadNamedState);
IDW_NEXTSLOT.SetBindings(Global.Config.NextSlot);
IDW_PREVIOUSSLOT.SetBindings(Global.Config.PreviousSlot);
IDW_RamWatch.SetBindings(Global.Config.RamWatch);
IDW_RamSearch.SetBindings(Global.Config.RamSearch);
IDW_RamPoke.SetBindings(Global.Config.RamPoke);
IDW_HexEditor.SetBindings(Global.Config.HexEditor);
IDW_LuaConsole.SetBindings(Global.Config.LuaConsole);
IDW_Cheats.SetBindings(Global.Config.Cheats);
IDW_OpenROM.SetBindings(Global.Config.OpenROM);
IDW_CloseROM.SetBindings(Global.Config.CloseROM);
IDW_DisplayFPS.SetBindings(Global.Config.FPSBinding);
IDW_FrameCounter.SetBindings(Global.Config.FrameCounterBinding);
IDW_LagCounter.SetBindings(Global.Config.LagCounterBinding);
IDW_InputDisplay.SetBindings(Global.Config.InputDisplayBinding);
IDW_TOGGLEREADONLY.SetBindings(Global.Config.ReadOnlyToggleBinding);
IDW_PLAYMOVIE.SetBindings(Global.Config.PlayMovieBinding);
IDW_RECORDMOVIE.SetBindings(Global.Config.RecordMovieBinding);
IDW_STOPMOVIE.SetBindings(Global.Config.StopMovieBinding);
IDW_PLAYBEGINNING.SetBindings(Global.Config.PlayBeginningBinding);
IDW_VOLUP.SetBindings(Global.Config.VolUpBinding);
IDW_VOLDOWN.SetBindings(Global.Config.VolDownBinding);
IDW_TOGGLEMTRACK.SetBindings(Global.Config.ToggleMultiTrack);
IDW_SELECTNONE.SetBindings(Global.Config.MTRecordNone);
IDW_MTSELECTALL.SetBindings(Global.Config.MTRecordAll);
IDW_MTINCPLAYER.SetBindings(Global.Config.MTIncrementPlayer);
IDW_MTDECPLAYER.SetBindings(Global.Config.MTDecrementPlayer);
IDW_RESET.SetBindings(Global.Config.SoftResetBinding);
}
private void button2_Click(object sender, EventArgs e)
{

View File

@ -7,160 +7,146 @@ namespace BizHawk.MultiClient
{
public class InputWidget : TextBox
{
private Timer timer = new Timer();
public InputWidget()
int MaxBind = 4; //Max number of bindings allowed
private Timer timer = new Timer();
public bool AutoTab = true;
string[] Bindings = new string[4];
string wasPressed = "";
public InputWidget()
{
this.ContextMenu = new ContextMenu();
this.timer.Tick += new System.EventHandler(this.Timer_Tick);
this.timer.Tick += new System.EventHandler(this.Timer_Tick);
InitializeBindings();
}
public List<IBinding> Bindings = new List<IBinding>();
public bool AutoTab = true;
bool ctrlWasPressed = false;
bool altWasPressed = false;
bool shiftWasPressed = false;
string TempBindingStr = ""; //TODO: remove me, this is for a proof of concept
protected override void OnEnter(EventArgs e)
{
timer.Start();
base.OnEnter(e);
}
protected override void OnLeave(EventArgs e)
{
timer.Stop();
this.Text = TempBindingStr;
base.OnLeave(e);
}
private void Timer_Tick(object sender, EventArgs e)
{
Input.Update();
TempBindingStr = Input.GetPressedKey();
if (TempBindingStr != null)
{
// just for debugging. not really sure how to rebind from inside the timer?
MessageBox.Show(TempBindingStr);
}
}
void UpdateLabel()
public InputWidget(int maxBindings)
{
if (Bindings.Count == 0)
{
Text = "";
}
else
{
Text = "";
for (int x = 0; x < Bindings.Count; x++)
Text += Bindings[x].ToString();
}
Update();
this.ContextMenu = new ContextMenu();
this.timer.Tick += new System.EventHandler(this.Timer_Tick);
MaxBind = maxBindings;
Bindings = new string[MaxBind];
InitializeBindings();
}
protected override void OnKeyDown(KeyEventArgs e)
private void InitializeBindings()
{
/*
e.Handled = true;
if (e.KeyCode == Keys.ControlKey) return;
if (e.KeyCode == Keys.ShiftKey) return;
if (e.KeyCode == Keys.Menu) return;
if (e.KeyCode != Keys.Escape)
for (int x = 0; x < MaxBind; x++)
{
KeyboardBinding kb = new KeyboardBinding();
kb.key = e.KeyCode;
kb.modifiers = e.Modifiers;
Bindings.Clear();
Bindings.Add(kb);
UpdateLabel();
Bindings[x] = "";
}
else
}
protected override void OnEnter(EventArgs e)
{
timer.Start();
base.OnEnter(e);
Input.Update();
wasPressed = Input.GetPressedKey();
}
protected override void OnLeave(EventArgs e)
{
timer.Stop();
UpdateLabel();
base.OnLeave(e);
}
private void Timer_Tick(object sender, EventArgs e)
{
ReadKeys();
}
private void ReadKeys()
{
Input.Update();
string TempBindingStr = Input.GetPressedKey();
if (wasPressed != "" && TempBindingStr == wasPressed) return;
if (TempBindingStr != null)
{
Bindings.Clear();
if (TempBindingStr == "Escape")
{
ClearBindings();
Increment();
return;
}
if (TempBindingStr == "Alt+F4")
return;
Bindings[0] = TempBindingStr;
UpdateLabel();
Increment();
}
if (e.KeyCode == Keys.F4)
e.Handled = false;
if (AutoTab)
this.Parent.SelectNextControl(this, true, true, true, true);
*/
}
protected override void OnKeyUp(KeyEventArgs e)
{
if (e.KeyData == Keys.ControlKey)
if (e.KeyCode == Keys.F4 && e.Modifiers == Keys.Alt)
{
if (ctrlWasPressed)
{
KeyboardBinding kb = new KeyboardBinding();
kb.key = Keys.ControlKey;
Bindings.Clear();
Bindings.Add(kb);
UpdateLabel();
this.Parent.SelectNextControl(this, true, true, true, true);
ctrlWasPressed = false;
shiftWasPressed = false;
altWasPressed = false;
}
else
{
ctrlWasPressed = true;
shiftWasPressed = false;
altWasPressed = false;
BackColor = SystemColors.ControlLight;
}
}
else if (e.KeyData == Keys.ShiftKey)
{
if (shiftWasPressed)
{
KeyboardBinding kb = new KeyboardBinding();
kb.key = Keys.ShiftKey;
Bindings.Clear();
Bindings.Add(kb);
UpdateLabel();
this.Parent.SelectNextControl(this, true, true, true, true);
ctrlWasPressed = false;
shiftWasPressed = false;
altWasPressed = false;
}
else
{
shiftWasPressed = true;
altWasPressed = false;
ctrlWasPressed = false;
BackColor = SystemColors.ControlLight;
}
}
else if (e.KeyData == Keys.Menu)
{
if (altWasPressed)
{
KeyboardBinding kb = new KeyboardBinding();
kb.key = Keys.Menu;
Bindings.Clear();
Bindings.Add(kb);
UpdateLabel();
this.Parent.SelectNextControl(this, true, true, true, true);
ctrlWasPressed = false;
shiftWasPressed = false;
altWasPressed = false;
}
else
{
altWasPressed = true;
ctrlWasPressed = false;
shiftWasPressed = false;
BackColor = SystemColors.ControlLight;
}
base.OnKeyUp(e);
}
wasPressed = "";
}
base.OnKeyUp(e);
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyCode == Keys.F4 && e.Modifiers == Keys.Alt)
{
base.OnKeyDown(e);
}
e.Handled = true;
}
// Advances to the next widget or the next binding depending on the autotab setting
private void Increment()
{
if (AutoTab)
this.Parent.SelectNextControl(this, true, true, true, true);
}
public void ClearBindings()
{
for (int x = 0; x < MaxBind; x++)
Bindings[x] = "";
}
public void UpdateLabel()
{
Text = "";
for (int x = 0; x < MaxBind; x++)
{
if (Bindings[x].Length > 0)
{
Text += Bindings[x];
if (x < MaxBind - 1 && Bindings[x+1].Length > 0)
Text += ", ";
}
}
}
public void SetBindings(string bindingsString)
{
Text = "";
ClearBindings();
string str = bindingsString.Trim();
int x;
for (int i = 0; i < MaxBind; i++)
{
str = str.Trim();
x = str.IndexOf(',');
if (x < 0)
{
Bindings[i] = str;
str = "";
}
else
{
Bindings[i] = str.Substring(0, x);
str = str.Substring(x + 1, str.Length - x - 1);
}
}
UpdateLabel();
}
protected override void OnKeyPress(KeyPressEventArgs e)
@ -184,89 +170,9 @@ namespace BizHawk.MultiClient
{
if (keyData == Keys.Tab)
{
KeyboardBinding kb = new KeyboardBinding();
kb.key = keyData;
Bindings.Clear();
Bindings.Add(kb);
UpdateLabel();
ReadKeys();
}
return false;
}
}
public class KeyboardBinding : IBinding
{
public override string ToString()
{
// Convert Windows key names to SlimDX key names
string str = "";
str += key.ToString();
if (str.Length == 2 && str == "F4") //Don't allow mapping of alt+f4
if ((modifiers & Keys.Alt) != 0)
return "";
if (str.Length == 10 && str == "ControlKey")
str = "Ctrl";
if (str.Length == 4 && str == "Menu")
str = "Alt";
if (str.Length == 8 && str == "ShiftKey")
str = "Shift";
if (str.Length == 2 && str == "Up")
str = "UpArrow";
if (str.Length == 4 && str == "Down")
str = "DownArrow";
if (str.Length == 4 && str == "Left")
str = "LeftArrow";
if (str.Length == 5 && str == "Right")
str = "RightArrow";
if (str.Length >= 6 && str.Substring(0, 6) == "NumPad")
str = str.Insert(3, "ber");
if (str.Length == 7 && str.Substring(0, 7) == "Decimal")
str = "NumberPadPeriod";
if (str.Length == 6 && str.Substring(0, 6) == "Divide")
str = "NumberPadSlash";
if (str.Length == 8 && str.Substring(0, 8) == "Multiply")
str = "NumberPadStar";
if (str.Length == 8 && str.Substring(0, 8) == "Subtract")
str = "NumberPadMinus";
if (str.Length == 3 && str.Substring(0, 3) == "Add")
str = "NumberPadPlus";
if (str.Length == 4 && str == "Oem5")
str = "BackSlash";
if (str.Length == 4 && str == "Oem6")
str = "RightBracket";
if (str.Length == 4 && str == "Next")
str = "PageDown";
if (str.Length == 11 && str == "OemQuestion")
str = "Slash";
if (str.Length == 8 && str == "Oemtilde")
str = "Grave";
if (str.Length == 8 && str == "Oemcomma")
str = "Comma";
if (str.Length > 3)
{
if (str.Substring(0, 3) == "Oem")
str = str.Substring(3, str.Length - 3);
}
//Oem Removed now removed from these but they still need conversion
if (str.Length == 12 && str.Substring(0, 12) == "OpenBrackets")
str = "LeftBracket";
if ((modifiers & Keys.Shift) != 0)
str = str.Insert(0, "Shift+");
if ((modifiers & Keys.Control) != 0)
str = str.Insert(0, "Ctrl+");
if ((modifiers & Keys.Alt) != 0)
str = str.Insert(0, "Alt+");
return str;
}
public Keys key;
public Keys modifiers;
}
public interface IBinding
{
}
}