Skip to content

rust: Port the Windows virtual-key table and key names #3076

Closed

Description

@rdoupe

Unit

Port the Windows virtual-key table, the key name route and the Meta rule of libobs/obs-windows.c.h to rust/obs-hotkey, as a new module windows_keys, next to the X11 key map (nix_x11_keys) and the macOS key map (cocoa_keys). On Windows, libobs uses them when it fills the hotkey platform's virtual-key table, in the hotkey thread's "is this key down" poll, for each key's name in Settings > Hotkeys, and in the public obs_key_from_virtual_key / obs_key_to_virtual_key. These decisions move:

  • get_virtual_key() (355-952): the virtual key of each obs key (mouse 1 to 5 the button VKs, the OBS_KEY_VK_* keys their VKs, every other key 0);
  • obs_hotkeys_platform_is_pressed() (978-986): Meta is down when either Windows key is; any other key asks its own VK;
  • obs_key_to_str() (988-1041), the name route: none, F13 to F24 by number, Mouse 1 to 29, Pause and Meta by translation, otherwise the scan code (with the extended bit for 11 VKs) and the system name unless the key is an OBS_KEY_VK_* key or the scan code is 0;
  • obs_key_from_virtual_key() (1043-1054): the first obs key with the VK;
  • obs_key_to_virtual_key() (1056-1062): Meta is VK_LWIN, any other key its table entry;
  • obs_key_combination_to_str() (1080-1097): the order Control, Meta (Windows), Alt, Shift, then the key.

These stay in C: GetAsyncKeyState, MapVirtualKey, GetKeyNameTextW, the translation lookups, every dstr_* call, add_combo_key's joins, the platform context's allocation and free, and everything else in the file (system info, symbols, crash handler, host hooks).

Phase and position

Phase 6, Windows host code; the Windows counterpart of the X11 key map (#2903) and macOS key map (#2917) ports. Tracking: #4.

Dependencies and existing tests

  • No dependency to land first; no open PR touches obs-windows.c.h or the windows+ unity group.
  • Real libobs: the hotkey tests do not reach these functions on Windows.
  • No characterization: test_windows_keys_steps lands first in the same PR. It builds the moved C file on its own (no Windows header: the VK values it needs are defined in its header and _Static_asserted against winuser.h in obs-windows.c.h), so it runs on every OS.

Notes

One PR, separate commits: the behaviour-neutral move into libobs/obs-windows-keys.c.h (hidden functions on plain values; the table stays in the platform context as today, read only where it was), characterization, RED, GREEN (group libobs.ported-windows-keys in the Windows ported sources), Tier 3 (every key from -1 to past OBS_KEY_LAST_VALUE, every VK 0 to 255, every modifier mask), docs.

Intentional difference, fixed in the port:

  • obs_key_to_virtual_key on Windows returns 0 for a key outside 0 .. OBS_KEY_LAST_VALUE - 1; C indexes the table with it, past its end. OBS's own callers pass keys in range; a script or plugin calling the exported function might not. obs_key_to_str and the pressed poll reach it with the same key.

Parity note (characterized, not changed): obs_key_from_virtual_key(VK_LWIN) gives OBS_KEY_VK_LWIN, while obs_key_to_virtual_key(OBS_KEY_META) gives VK_LWIN, so Meta does not round-trip.

Activity

  1. added
    enhancement
    port
    on Oct 30, 2026
  2. rdoupe commented on Oct 30, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: #3076

    Plan, one PR with separate commits:

    1. libobs: Move the virtual-key table, the first-match and Meta lookups, the pressed check's Meta rule, the key name route (with the scan code's extended bit) and the combination order into libobs/obs-windows-keys.c.h: hidden functions on plain values, no Windows header (the VK values are defined in its header and _Static_asserted against winuser.h in obs-windows.c.h), behaviour-neutral (checked by building master's and the moved functions side by side on the same inputs).
    2. Characterization: test_windows_keys_steps, building the moved file on its own, on every OS.
    3. RED: Tier 1 obs_hotkey::windows_keys against todo!() stubs.
    4. GREEN: the safe core and src/ffi/windows_keys.rs, group libobs.ported-windows-keys in the Windows ported sources, with the key range check in obs_key_to_virtual_key.
    5. Tier 3 parity against the C with a mutation check.
    6. Docs.

    I expect the draft PR today, within a few hours.

  3. added
    ready
    on Oct 30, 2026
  4. rdoupe commented on Oct 30, 2026

    @rdoupe
    CollaboratorAuthor

    Fixed by PR #3078 (merged through the merge queue): the Windows virtual-key table, the Meta rule, the key name route and the combination order now run from rust/obs-hotkey (windows_keys), with the characterization, Tier 1, Tier 3 parity and mutation checks.

    Left: test_windows_keys_steps_rust builds on Linux only; its macOS and Windows links are not worked out. That is the follow-up issue #3104. Nothing else of this unit is left.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementportready

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions