Skip to content

Commit

Permalink
fix(windows): map OsCode btns to VK btns, reduce logging (#223)
Browse files Browse the repository at this point in the history
* fix(wintercept): don't intercept mouse if hwid unset

* fix(windows): map OsCode btns to VK btns

* fix(wintercept): exclude non-button mouse events
  • Loading branch information
jtroo authored Dec 24, 2022
1 parent 39d76a5 commit e8a3164
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/kanata/windows/interception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ impl Kanata {
state: ic::KeyState::empty(),
information: 0,
}; 32];
intrcptn.set_filter(ic::is_mouse, ic::Filter::MouseFilter(ic::MouseState::all()));

let mouse_to_intercept_hwid: Option<[u8; HWID_ARR_SZ]> = kanata
.lock()
Expand All @@ -37,16 +36,27 @@ impl Kanata {
hwid
})
});
if mouse_to_intercept_hwid.is_some() {
intrcptn.set_filter(
ic::is_mouse,
ic::Filter::MouseFilter(
ic::MouseState::all()
& (!ic::MouseState::WHEEL)
& (!ic::MouseState::HWHEEL)
& (!ic::MouseState::MOVE),
),
);
}
let mut is_dev_interceptable: HashMap<ic::Device, bool> = HashMap::default();

loop {
let dev = intrcptn.wait_with_timeout(std::time::Duration::from_millis(1));
if dev > 0 {
let num_strokes = intrcptn.receive(dev, &mut strokes) as usize;
for i in 0..num_strokes {
log::debug!("got stroke {:?}", strokes[i]);
let mut key_event = match strokes[i] {
ic::Stroke::Keyboard { state, .. } => {
log::debug!("got stroke {:?}", strokes[i]);
let code = match OsCode::try_from(strokes[i]) {
Ok(c) => c,
_ => {
Expand All @@ -62,9 +72,8 @@ impl Kanata {
KeyEvent { code, value }
}
ic::Stroke::Mouse { state, .. } => {
log::trace!("matched on mouse stroke");
if let Some(hwid) = mouse_to_intercept_hwid {
log::trace!("checking mouse state to event");
log::trace!("checking mouse stroke {:?}", strokes[i]);
if let Some(event) = mouse_state_to_event(
dev,
&hwid,
Expand Down
5 changes: 5 additions & 0 deletions src/keys/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,11 @@ impl OsCode {
OsCode::KEY_RO => 0xC1,
OsCode::KEY_HENKAN => VK_CONVERT,
OsCode::KEY_MUHENKAN => VK_NONCONVERT,
OsCode::BTN_LEFT => VK_LBUTTON,
OsCode::BTN_RIGHT => VK_RBUTTON,
OsCode::BTN_MIDDLE => VK_MBUTTON,
OsCode::BTN_SIDE => VK_XBUTTON1,
OsCode::BTN_EXTRA => VK_XBUTTON2,
_ => 0,
}
}
Expand Down

0 comments on commit e8a3164

Please sign in to comment.