summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorGuilherme Felipe <guilhermefelipecgs@gmail.com>2019-04-15 14:41:44 -0300
committerGuilherme Felipe <guilhermefelipecgs@gmail.com>2019-04-27 12:05:12 -0300
commitc709dfdf06f6b09b61c1f34ff5a32cbfa8acc523 (patch)
treeeb330830f3f29f623134806d29ac0e1cc09a1fe1 /main
parent260530f01caa8ea3e2fb7bfda04f4bd718ae14f5 (diff)
[Input] Release keys/actions pressed if window loses focus
Co-authored-by: bruvzg <7645683+bruvzg@users.noreply.github.com> Co-authored-by: Marcelo Fernandez <marcelofg55@gmail.com>
Diffstat (limited to 'main')
-rw-r--r--main/input_default.cpp13
-rw-r--r--main/input_default.h1
2 files changed, 14 insertions, 0 deletions
diff --git a/main/input_default.cpp b/main/input_default.cpp
index 6c3252ad1a..a939d77a1e 100644
--- a/main/input_default.cpp
+++ b/main/input_default.cpp
@@ -677,6 +677,19 @@ void InputDefault::set_use_accumulated_input(bool p_enable) {
use_accumulated_input = p_enable;
}
+void InputDefault::release_pressed_events() {
+
+ flush_accumulated_events(); // this is needed to release actions strengths
+
+ keys_pressed.clear();
+ joy_buttons_pressed.clear();
+ _joy_axis.clear();
+
+ for (Map<StringName, InputDefault::Action>::Element *E = action_state.front(); E; E = E->next()) {
+ action_release(E->key());
+ }
+}
+
InputDefault::InputDefault() {
use_accumulated_input = true;
diff --git a/main/input_default.h b/main/input_default.h
index f9b4cbbd57..80ee17656c 100644
--- a/main/input_default.h
+++ b/main/input_default.h
@@ -272,6 +272,7 @@ public:
virtual void flush_accumulated_events();
virtual void set_use_accumulated_input(bool p_enable);
+ virtual void release_pressed_events();
InputDefault();
};