From 7f984db97bcb8602ca28d70569cfbe3ffddae55e Mon Sep 17 00:00:00 2001 From: jtroo Date: Wed, 22 Nov 2023 00:15:43 -0800 Subject: [PATCH] fix(wintercept): send Esc for unmapped oscode (#637) --- src/oskbd/windows/interception.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/oskbd/windows/interception.rs b/src/oskbd/windows/interception.rs index 434575345..825cb2829 100644 --- a/src/oskbd/windows/interception.rs +++ b/src/oskbd/windows/interception.rs @@ -2,7 +2,7 @@ use std::io; -use kanata_interception::{Interception, KeyState, MouseFlags, MouseState, Stroke}; +use kanata_interception::{Interception, KeyState, MouseFlags, MouseState, ScanCode, Stroke}; use super::OsCodeWrapper; use crate::kanata::CalculatedMouseMove; @@ -16,8 +16,14 @@ pub struct InputEvent(pub Stroke); impl InputEvent { fn from_oscode(code: OsCode, val: KeyValue) -> Self { - let mut stroke = - Stroke::try_from(OsCodeWrapper(code)).expect("kanata only sends mapped `OsCode`s"); + let mut stroke = Stroke::try_from(OsCodeWrapper(code)).unwrap_or_else(|_| { + log::error!("Trying to send unmapped oscode '{code:?}', sending esc instead"); + Stroke::Keyboard { + code: ScanCode::Esc, + state: KeyState::empty(), + information: 0, + } + }); match &mut stroke { Stroke::Keyboard { state, .. } => { state.set(