(&mut self, key: KeyCode, is_down: bool)
| 48 | /// Apply a key transition and update one-frame pressed/released edges. |
| 49 | #[inline] |
| 50 | pub fn set_key_state(&mut self, key: KeyCode, is_down: bool) { |
| 51 | let idx = key.as_index(); |
| 52 | let word = idx / 64; |
| 53 | let bit = 1_u64 << (idx % 64); |
| 54 | let was_down = self.down[word] & bit != 0; |
| 55 | |
| 56 | if is_down { |
| 57 | if !was_down { |
| 58 | self.down[word] |= bit; |
| 59 | self.pressed[word] |= bit; |
| 60 | } |
| 61 | } else if was_down { |
| 62 | self.down[word] &= !bit; |
| 63 | self.released[word] |= bit; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | // ---- Query ---- |
| 68 |