key_map.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include <tuple>
  7. #include "core/hle/service/hid/hid.h"
  8. class EmuWindow;
  9. namespace KeyMap {
  10. enum class IndirectTarget {
  11. CIRCLE_PAD_UP,
  12. CIRCLE_PAD_DOWN,
  13. CIRCLE_PAD_LEFT,
  14. CIRCLE_PAD_RIGHT,
  15. CIRCLE_PAD_MODIFIER,
  16. };
  17. /**
  18. * Represents a key mapping target. It can be a PadState that represents 3DS real buttons,
  19. * or an IndirectTarget.
  20. */
  21. struct KeyTarget {
  22. bool direct;
  23. union {
  24. u32 direct_target_hex;
  25. IndirectTarget indirect_target;
  26. } target;
  27. KeyTarget() : direct(true) {
  28. target.direct_target_hex = 0;
  29. }
  30. KeyTarget(Service::HID::PadState pad) : direct(true) {
  31. target.direct_target_hex = pad.hex;
  32. }
  33. KeyTarget(IndirectTarget i) : direct(false) {
  34. target.indirect_target = i;
  35. }
  36. };
  37. /**
  38. * Represents a key for a specific host device.
  39. */
  40. struct HostDeviceKey {
  41. int key_code;
  42. int device_id; ///< Uniquely identifies a host device
  43. bool operator<(const HostDeviceKey &other) const {
  44. return std::tie(key_code, device_id) <
  45. std::tie(other.key_code, other.device_id);
  46. }
  47. bool operator==(const HostDeviceKey &other) const {
  48. return std::tie(key_code, device_id) ==
  49. std::tie(other.key_code, other.device_id);
  50. }
  51. };
  52. extern const std::array<KeyTarget, Settings::NativeInput::NUM_INPUTS> mapping_targets;
  53. /**
  54. * Generates a new device id, which uniquely identifies a host device within KeyMap.
  55. */
  56. int NewDeviceId();
  57. /**
  58. * Maps a device-specific key to a target (a PadState or an IndirectTarget).
  59. */
  60. void SetKeyMapping(HostDeviceKey key, KeyTarget target);
  61. /**
  62. * Clears all key mappings belonging to one device.
  63. */
  64. void ClearKeyMapping(int device_id);
  65. /**
  66. * Maps a key press actions and call the corresponding function in EmuWindow
  67. */
  68. void PressKey(EmuWindow& emu_window, HostDeviceKey key);
  69. /**
  70. * Maps a key release actions and call the corresponding function in EmuWindow
  71. */
  72. void ReleaseKey(EmuWindow& emu_window, HostDeviceKey key);
  73. }