@@ -65,6 +65,7 @@ struct ProjectConfig {
6565#[ derive( Debug ) ]
6666pub struct InputManager {
6767 key_history : Vec < glfw:: Key > ,
68+ key_combination_used : bool ,
6869 keys_down : HashSet < glfw:: Key > ,
6970 keys_pressed : HashSet < glfw:: Key > ,
7071 keys_released : HashSet < glfw:: Key > ,
@@ -77,6 +78,7 @@ impl InputManager {
7778 pub fn new ( ) -> Self {
7879 Self {
7980 key_history : Vec :: new ( ) ,
81+ key_combination_used : false ,
8082 keys_down : HashSet :: new ( ) ,
8183 keys_pressed : HashSet :: new ( ) ,
8284 keys_released : HashSet :: new ( ) ,
@@ -100,6 +102,7 @@ impl InputManager {
100102 match event {
101103 glfw:: WindowEvent :: Key ( key, _, action, _) => match action {
102104 glfw:: Action :: Press => {
105+ self . key_combination_used = false ;
103106 if !self . keys_down . contains ( & key) {
104107 self . keys_pressed . insert ( key) ;
105108 }
@@ -137,6 +140,12 @@ impl InputManager {
137140 & self . key_history
138141 }
139142
143+ pub fn combination_pressed ( & mut self , key_codes : & [ glfw:: Key ] ) -> bool {
144+ let previous_key_combination_used = self . key_combination_used ;
145+ self . key_combination_used = self . key_history ( ) . ends_with ( & key_codes) ;
146+ self . key_combination_used && !previous_key_combination_used
147+ }
148+
140149 pub fn is_key_down ( & self , key : glfw:: Key ) -> bool {
141150 self . keys_down . contains ( & key)
142151 }
0 commit comments