Keymap.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // Keymap.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Text;
  13. using Microsoft.Xna.Framework.Input;
  14. using Microsoft.Xna.Framework;
  15. using System.Diagnostics;
  16. #endregion
  17. namespace Spacewar
  18. {
  19. class Keymap
  20. {
  21. private Dictionary<GamePadKeys, List<Keys>> bindings;
  22. // currently a hack so I can bind the same keyboard key to multiple gamepad keys
  23. public Keymap()
  24. {
  25. bindings = new Dictionary<GamePadKeys, List<Keys>>();
  26. }
  27. public void Add(GamePadKeys gk, Keys k)
  28. {
  29. List<Keys> keyboardkey = new List<Keys>();
  30. keyboardkey.Add(k);
  31. if (bindings.ContainsKey(gk))
  32. {
  33. bindings.Remove(gk);
  34. bindings.Add(gk, keyboardkey);
  35. }
  36. else
  37. {
  38. bindings.Add(gk, keyboardkey);
  39. }
  40. }
  41. public Keys Get(GamePadKeys gk)
  42. {
  43. return bindings[gk][0];
  44. }
  45. }
  46. }