@@ -15,15 +15,15 @@ namespace sds
1515 // / </summary>
1616 class KeyboardTranslator
1717 {
18- const std::string ERR_BAD_VK = " Either WordData.MappedToVK OR WordData.SendElementVK is <= 0" ;
19- const std::string ERR_DUP_KEYUP = " Sent a duplicate keyup event to handle thumbstick direction changing behavior." ;
2018 using ClockType = std::chrono::high_resolution_clock;
2119 using PointInTime = std::chrono::time_point<ClockType>;
2220 using InpType = sds::KeyboardKeyMap::ActionType;
21+ const std::string ERR_BAD_VK{ " Either WordData.MappedToVK OR WordData.SendElementVK is <= 0" };
22+ const std::string ERR_DUP_KEYUP{ " Sent a duplicate keyup event to handle thumbstick direction changing behavior." };
2323 private:
24- Utilities::SendKeyInput m_key_send;
25- std::vector<KeyboardKeyMap> m_map_token_info;
26- KeyboardPlayerInfo m_local_player;
24+ Utilities::SendKeyInput m_key_send{} ;
25+ std::vector<KeyboardKeyMap> m_map_token_info{} ;
26+ KeyboardPlayerInfo m_local_player{} ;
2727 public:
2828 explicit KeyboardTranslator (const KeyboardPlayerInfo &p) : m_local_player(p)
2929 {
@@ -50,6 +50,17 @@ namespace sds
5050 }
5151 }
5252 }
53+ // / <summary>Call this function to send key-ups for any in-progress key presses.</summary>
54+ void CleanupInProgressEvents ()
55+ {
56+ for (auto &m: m_map_token_info)
57+ {
58+ if (m.LastAction == InpType::KEYDOWN || m.LastAction == InpType::KEYREPEAT)
59+ {
60+ this ->DoOvertaking (m);
61+ }
62+ }
63+ }
5364 std::string AddKeyMap (KeyboardKeyMap w)
5465 {
5566 std::string result = CheckForVKError (w);
@@ -58,11 +69,11 @@ namespace sds
5869 m_map_token_info.push_back (w);
5970 return " " ;
6071 }
61- void ClearMap ()
72+ void ClearMaps () noexcept
6273 {
6374 m_map_token_info.clear ();
6475 }
65- std::vector<KeyboardKeyMap> GetMaps () const
76+ std::vector<KeyboardKeyMap> GetMaps () const noexcept
6677 {
6778 return m_map_token_info;
6879 }
@@ -91,9 +102,7 @@ namespace sds
91102 }
92103 }
93104 }
94- // / <summary>
95- // / Normal keypress simulation logic.
96- // / </summary>
105+ // / <summary>Normal keypress simulation logic.</summary>
97106 void Normal (KeyboardKeyMap &detail, const XINPUT_KEYSTROKE &stroke)
98107 {
99108 const bool DoDown = (detail.LastAction == InpType::NONE) && (stroke.Flags & static_cast <WORD>(InpType::KEYDOWN));
@@ -111,17 +120,15 @@ namespace sds
111120 SendTheKey (detail, false , InpType::KEYUP);
112121 }
113122 }
114- // Does the key send call, updates LastAction and updates LastSentTime
115- void SendTheKey (KeyboardKeyMap& mp, const bool keyDown, KeyboardKeyMap::ActionType action)
123+ // / <summary> Does the key send call, updates LastAction and updates LastSentTime</summary>
124+ void SendTheKey (KeyboardKeyMap& mp, const bool keyDown, KeyboardKeyMap::ActionType action) noexcept
116125 {
117126 // std::cerr << mp << std::endl; // temp logging
118127 mp.LastAction = action;
119128 m_key_send.SendScanCode (mp.MappedToVK , keyDown);
120129 mp.LastSentTime .Reset (KeyboardSettings::MICROSECONDS_DELAY_KEYREPEAT); // update last sent time
121130 }
122- // / <summary>
123- // / Check to see if a different axis of the same thumbstick has been pressed already
124- // / </summary>
131+ // / <summary>Check to see if a different axis of the same thumbstick has been pressed already</summary>
125132 // / <param name="detail">Newest element being set to keydown state</param>
126133 // / <param name="outOvertaken">out key set to the one being overtaken</param>
127134 // / <returns>true if is overtaking a thumbstick direction already depressed</returns>
@@ -151,7 +158,7 @@ namespace sds
151158 }
152159 return false ;
153160 }
154- void DoOvertaking (KeyboardKeyMap &detail)
161+ void DoOvertaking (KeyboardKeyMap &detail) noexcept
155162 {
156163 SendTheKey (detail, false , InpType::KEYUP);
157164 }
0 commit comments