You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my code, I need smooth repeating keys. We do this with a special gadget that takes miniquad key events, and tracks the time. This allows add an initial delay and time between actions.
structPressedKeysSmoothRepeat{/// When holding keys, we track from start and last sent time./// This is useful for initial delay and smooth scrolling.pressed_keys:HashMap<String,RepeatingKeyTimer>,/// Initial delay before allowing keysstart_delay:u32,/// Minimum time between repeated keysstep_time:u32,}implPressedKeysSmoothRepeat{fnnew(start_delay:u32,step_time:u32) -> Self{Self{pressed_keys:HashMap::new(), start_delay, step_time }}fnkey_down(&mutself,key:&str,repeat:bool) -> u32{if !repeat {return1;}// Insert key if not existsif !self.pressed_keys.contains_key(key){self.pressed_keys.insert(key.to_string(),RepeatingKeyTimer::new());}let repeater = self.pressed_keys.get_mut(key).expect("repeat map");
repeater.update(self.start_delay,self.step_time)}fnkey_up(&mutself,key:&str){self.pressed_keys.remove(key);}}structRepeatingKeyTimer{start:Instant,actions:u32,}implRepeatingKeyTimer{fnnew() -> Self{Self{start:Instant::now(),actions:0}}fnupdate(&mutself,start_delay:u32,step_time:u32) -> u32{let elapsed = self.start.elapsed().as_millis();if elapsed < start_delay asu128{return0}let total_actions = ((elapsed - start_delay asu128) / step_time asu128)asu32;let remaining_actions = total_actions - self.actions;self.actions = total_actions;
remaining_actions
}}
We need the key_up event to remove the key from the hashmap - see PressedKeysSmoothRepeat::key_up(), but there is no key up event for insert_char.
What if insert_char is deprecated, and we replace KeyCodes in key_up/key_down with xkb keysyms?
The text was updated successfully, but these errors were encountered:
narodnik
changed the title
inset_char() and key_down/key_up should be unified, and use keysyms directly
insert_char() and key_down/key_up should be unified, and use keysyms directly
Jul 4, 2024
In my code, I need smooth repeating keys. We do this with a special gadget that takes miniquad key events, and tracks the time. This allows add an initial delay and time between actions.
We need the key_up event to remove the key from the hashmap - see
PressedKeysSmoothRepeat::key_up()
, but there is no key up event forinsert_char
.What if insert_char is deprecated, and we replace KeyCodes in key_up/key_down with xkb keysyms?
The text was updated successfully, but these errors were encountered: