// This is to allow development of this feature on devices without consumer control buttons.
This is to allow development of this feature on devices without consumer control buttons.
This is to allow development of this feature on devices without consumer control buttons .
fn handle_keyboard_event(
        &mut self,
        context: &mut ViewAssistantContext,
        event: &input::Event,
        keyboard_event: &input::keyboard::Event,
    ) -> Result<(), Error> {
        const HID_USAGE_KEY_F11: u32 = 0x44;
        const HID_USAGE_KEY_F12: u32 = 0x45;
        fn keyboard_to_consumer_phase(
            phase: carnelian::input::keyboard::Phase,
        ) -> carnelian::input::consumer_control::Phase {
            match phase {
                carnelian::input::keyboard::Phase::Pressed => {
                    carnelian::input::consumer_control::Phase::Down
                }
                _ => carnelian::input::consumer_control::Phase::Up,
            }
        }
        let synthetic_event = match keyboard_event.hid_usage {
            HID_USAGE_KEY_F11 => Some(input::consumer_control::Event {
                button: ConsumerControlButton::VolumeDown,
                phase: keyboard_to_consumer_phase(keyboard_event.phase),
            }),
            HID_USAGE_KEY_F12 => Some(input::consumer_control::Event {
                button: ConsumerControlButton::VolumeUp,
                phase: keyboard_to_consumer_phase(keyboard_event.phase),
            }),
            _ => None,
        };
        if let Some(synthetic_event) = synthetic_event {
            self.handle_consumer_control_event(context, event, &synthetic_event)?;
        }
        Ok(())
    }
fn handle_keyboard_event ( & mut self , context : & mut ViewAssistantContext , event : & input :: Event , keyboard_event : & input :: keyboard :: Event , ) -> Result < ( ) , Error > { const HID_USAGE_KEY_F11 : u32 = 0x44 ; const HID_USAGE_KEY_F12 : u32 = 0x45 ; fn keyboard_to_consumer_phase ( phase : carnelian :: input :: keyboard :: Phase , ) -> carnelian :: input :: consumer_control :: Phase { match phase { carnelian :: input :: keyboard :: Phase :: Pressed => { carnelian :: input :: consumer_control :: Phase :: Down } _ => carnelian :: input :: consumer_control :: Phase :: Up , } } let synthetic_event = match keyboard_event . hid_usage { HID_USAGE_KEY_F11 => Some ( input :: consumer_control :: Event { button : ConsumerControlButton :: VolumeDown , phase : keyboard_to_consumer_phase ( keyboard_event . phase ) , } ) , HID_USAGE_KEY_F12 => Some ( input :: consumer_control :: Event { button : ConsumerControlButton :: VolumeUp , phase : keyboard_to_consumer_phase ( keyboard_event . phase ) , } ) , _ => None , } ; if let Some ( synthetic_event ) = synthetic_event { self . handle_consumer_control_event ( context , event , & synthetic_event ) ? ; } Ok ( ( ) ) }
This is to allow development of this feature on devices without consumer control buttons.
This is to allow development of this feature on devices without consumer control buttons .
&mut self
context
&mut ViewAssistantContext
event
&input::Event
keyboard_event
&input::keyboard::Event