Skip to content

fix: Num Lock injetado no Windows era descartado - #22

Merged
actus7 merged 1 commit into
masterfrom
fix/numlock-windows
Oct 30, 2026
Merged

actus7 merged 1 commit into
masterfrom
fix/numlock-windows

Conversation

@actus7

@actus7 actus7 commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Problema

De Windows para Windows, o Num Lock não funcionava no remoto.

Causa

O hook de teclado reporta NumLock como scancode 0x45 com LLKHF_EXTENDED. O injetor repassava com KEYEVENTF_SCANCODE | KEYEVENTF_EXTENDEDKEY, ou seja E0 45, que não mapeia para nenhuma tecla (MapVirtualKey(0xE045, MAPVK_VSC_TO_VK_EX) = 0, enquanto 0x45 → VK_NUMLOCK). Pause chega como 0x45 simples e seria injetado como NumLock.

Correção

Injector::send (native/src/lib.rs): NumLock sai como 0x45 sem a flag estendida; Pause sai por VK_PAUSE. Vale para qualquer servidor (Windows, mac, Linux), pois todos chegam ao mesmo injetor.

Testes

  • numlock_sai_sem_flag_estendida_e_pause_por_virtual_key
  • 42 testes do native ok, clippy limpo (toolchain GNU local)
  • Teste real Windows → Windows

🤖 Generated with Claude Code

O hook reporta NumLock como scancode 0x45 estendido, mas na injeção
E0 45 não mapeia para tecla nenhuma (MapVirtualKey devolve 0). NumLock
agora sai como 0x45 simples; Pause, que o hook reporta como 0x45
simples, sai por VK_PAUSE para não virar NumLock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 30, 2026 11:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — one test-coverage suggestion inline.

Reviewed changes: the single commit on fix/numlock-windows, covering native/src/lib.rs and CHANGELOG.md.

  • Injector::send key mapping: NumLock (0x45 extended) is now injected as a plain 0x45 scancode. Pause (0x45 non-extended) is injected via VK_PAUSE. Other keys behave as before, and release_all goes through the same mapping.
  • Regression test: numlock_sai_sem_flag_estendida_e_pause_por_virtual_key covers the new mapping.
  • Changelog: Unreleased / Fixed entry added.

The mapping logic reads correctly. VK_PAUSE resolves through the existing KeyboardAndMouse::* import. Held-key tracking in InputState still uses the original (scancode, extended) tuple, so releases map consistently. The real Windows to Windows check in the PR checklist is still open, and I could only review the Windows code by reading it.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using claude-sonnet-5-5 | 𝕏

Comment thread native/src/lib.rs
injector.send(Event::Key { scancode: 0x45, extended: true, down: true }).expect("numlock");
injector.send(Event::Key { scancode: 0x45, extended: false, down: false }).expect("pause");
let sent = SENT.with(|sent| sent.borrow().clone());
assert_eq!(sent, [(INPUT_KEYBOARD, 0x45, KEYEVENTF_SCANCODE), (INPUT_KEYBOARD, 0x45, KEYEVENTF_KEYUP)]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test name says Pause goes out "por virtual key", but record only captures (type, wScan, dwFlags) and drops wVk, and Pause is only sent as a key-up. Reverting the (0x45, false) arm to a plain scancode would still pass. Consider capturing wVk in record (or adding a dedicated assertion) and sending Pause down as well, so VK_PAUSE is actually asserted.

Technical details
# Pause virtual key is not asserted by the test

## Affected sites
- native/src/lib.rs:1226-1237 — `record` stores `(type, wScan, dwFlags)` only, so `wVk` is invisible to tests
- native/src/lib.rs:1244-1246 — Pause is sent only with `down: false`, and the expected tuple `(INPUT_KEYBOARD, 0x45, KEYEVENTF_KEYUP)` is identical to what a plain scancode path would produce

## Required outcome
- The test fails if the `(0x45, false)` arm stops using `VK_PAUSE`.

## Suggested approach (optional)
- Extend the `SENT` tuple (or add a second recorder) with `wVk`, and update the other assertions that destructure it, e.g. `release_all_solta_scancodes_injetados`.
- Send Pause with `down: true` too.

@actus7
actus7 merged commit 9860a1f into master Oct 30, 2026
6 checks passed
@actus7
actus7 deleted the fix/numlock-windows branch October 30, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants