use plushie_core::protocol::OutgoingEvent;
pub trait OutgoingEventKeyExt {
fn key_press(tag: impl Into<String>, data: &crate::runtime::KeyEventData) -> OutgoingEvent;
fn key_release(tag: impl Into<String>, data: &crate::runtime::KeyEventData) -> OutgoingEvent;
}
impl OutgoingEventKeyExt for OutgoingEvent {
fn key_press(tag: impl Into<String>, data: &crate::runtime::KeyEventData) -> OutgoingEvent {
let mut event = OutgoingEvent::tagged("key_press", tag);
event.modifiers = Some(crate::runtime::serialize_modifiers(data.modifiers));
event.value = Some(serde_json::json!({
"key": crate::runtime::serialize_key(&data.key),
"modified_key": crate::runtime::serialize_key(&data.modified_key),
"physical_key": crate::runtime::serialize_physical_key(&data.physical_key),
"location": crate::runtime::serialize_location(&data.location),
"text": data.text.as_deref(),
"repeat": data.repeat,
}));
event
}
fn key_release(tag: impl Into<String>, data: &crate::runtime::KeyEventData) -> OutgoingEvent {
let mut event = OutgoingEvent::tagged("key_release", tag);
event.modifiers = Some(crate::runtime::serialize_modifiers(data.modifiers));
event.value = Some(serde_json::json!({
"key": crate::runtime::serialize_key(&data.key),
"modified_key": crate::runtime::serialize_key(&data.modified_key),
"physical_key": crate::runtime::serialize_physical_key(&data.physical_key),
"location": crate::runtime::serialize_location(&data.location),
}));
event
}
}