diff --git a/src/bridge/keybindings.rs b/src/bridge/keybindings.rs index e3b0a39..0c67360 100644 --- a/src/bridge/keybindings.rs +++ b/src/bridge/keybindings.rs @@ -94,7 +94,7 @@ fn parse_keycode(keycode: VirtualKeyCode) -> Option<(&'static str, bool)> { } } -fn append_modifiers(modifiers: ModifiersState, keycode_text: &str, special: bool) -> String { +pub fn append_modifiers(modifiers: ModifiersState, keycode_text: &str, special: bool) -> String { let mut result = keycode_text.to_string(); let mut special = special; diff --git a/src/window.rs b/src/window.rs index 014e02b..4d2dba0 100644 --- a/src/window.rs +++ b/src/window.rs @@ -5,7 +5,7 @@ use std::time::{Duration, Instant}; use image::{load_from_memory, GenericImageView, Pixel}; use skulpin::{CoordinateSystem, RendererBuilder, PresentMode}; use skulpin::winit::dpi::LogicalSize; -use skulpin::winit::event::{ElementState, Event, MouseScrollDelta, StartCause, WindowEvent}; +use skulpin::winit::event::{ElementState, Event, MouseScrollDelta, StartCause, WindowEvent, ModifiersState}; use skulpin::winit::event_loop::{ControlFlow, EventLoop}; use skulpin::winit::window::{Icon, WindowBuilder}; use log::{info, debug, trace, error}; @@ -73,6 +73,9 @@ pub fn ui_loop() { let mut mouse_down = false; let mut mouse_pos = (0, 0); + let mut allow_next_char = false; + let mut next_char_modifiers = ModifiersState::empty(); + info!("Starting window event loop"); event_loop.run(move |event, _window_target, control_flow| { trace!("Window Event: {:?}", event); @@ -101,11 +104,28 @@ pub fn ui_loop() { }, .. } => { + if input.virtual_keycode == None { + allow_next_char = true; + }else { + allow_next_char = false; + } + next_char_modifiers = input.modifiers; + construct_keybinding_string(input) .map(UiCommand::Keyboard) .map(|keybinding_string| BRIDGE.queue_command(keybinding_string)); }, + Event::WindowEvent { + event: WindowEvent::ReceivedCharacter(c), + .. + } => { + if allow_next_char { + let keybinding = super::bridge::append_modifiers(next_char_modifiers, &c.to_string(), false); + BRIDGE.queue_command(UiCommand::Keyboard(keybinding)); + } + }, + Event::WindowEvent { event: WindowEvent::CursorMoved { position,