feat(libSceKeyboard): implement the keyboard library #225

Merged
adriadam10 merged 1 commit from upstream-pr/225 into main 2026-10-01 18:50:25 +00:00
adriadam10 commented 2026-10-01 17:00:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-01T17:00:43Z.


What

Implements all six libSceKeyboard exports, following the structure of libSceMouse.

  • KeyboardInput in libSceVideoOut forwards SDL key and window focus events from the existing event loop, the same way MouseInput does. SDL2 scancodes are USB HID usages, so they are passed as is; key repeats are ignored. Lock LEDs come from the SDL modifier state.
  • The library keeps the pressed keys (up to 16, in press order), the modifier bitmask (0xE0–0xE7) and the LEDs. Every change is queued in a 16-entry history for sceKeyboardRead; sceKeyboardReadState returns the current state. Losing focus releases all keys; closing the window reports a disconnect, as with the mouse.
  • sceKeyboardGetKey2Char translates the 101-key (US) arrangement: letters with Shift/Caps Lock, digits and symbols with Shift, keypad digits with Num Lock, Enter/Backspace/Tab/Space as \n \b \t ' '. Keys without a character return processed = false. The 106-key (Japanese) arrangement throws and is listed in TechnicalDebt.md.
  • Error codes 0x80DA0001–0x80DA0005 as in shadPS4; the open/close/read rules mirror libSceMouse.

KEYBOARD_MAX_KEYCODES in SceTypes.hpp goes from 6 to 16: KytyPS5 and SharpProspero both define SceKeyboardData with 16 key codes (96 bytes); with 6 the struct is 76 bytes. Layout is pinned with static_asserts.

Tested

Linux (CachyOS, GCC): new keyboard_input test (core/libs/prx/libSceKeyboard/tests/Keyboard.cpp) passes. It drives KeyboardInput with synthetic SDL events (window filter, repeats, modifiers, LEDs, focus loss, disconnect, 16-key limit, history overflow) and checks the character table. It fails on each of three injected bugs (one table entry changed, keys kept on focus loss, no 16-key limit). Full suite: 90/90 pass. Windows only through CI. No title tested: no keyboard title available.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4706904816 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/225). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-01T17:00:43Z. --- ### What Implements all six `libSceKeyboard` exports, following the structure of `libSceMouse`. - `KeyboardInput` in `libSceVideoOut` forwards SDL key and window focus events from the existing event loop, the same way `MouseInput` does. SDL2 scancodes are USB HID usages, so they are passed as is; key repeats are ignored. Lock LEDs come from the SDL modifier state. - The library keeps the pressed keys (up to 16, in press order), the modifier bitmask (`0xE0`–`0xE7`) and the LEDs. Every change is queued in a 16-entry history for `sceKeyboardRead`; `sceKeyboardReadState` returns the current state. Losing focus releases all keys; closing the window reports a disconnect, as with the mouse. - `sceKeyboardGetKey2Char` translates the 101-key (US) arrangement: letters with Shift/Caps Lock, digits and symbols with Shift, keypad digits with Num Lock, Enter/Backspace/Tab/Space as `\n \b \t ' '`. Keys without a character return `processed = false`. The 106-key (Japanese) arrangement throws and is listed in `TechnicalDebt.md`. - Error codes `0x80DA0001`–`0x80DA0005` as in shadPS4; the open/close/read rules mirror `libSceMouse`. `KEYBOARD_MAX_KEYCODES` in `SceTypes.hpp` goes from 6 to 16: [KytyPS5](https://github.com/KytyPS5/KytyPS5/blob/main/src/libs/libPad.cpp) and SharpProspero both define `SceKeyboardData` with 16 key codes (96 bytes); with 6 the struct is 76 bytes. Layout is pinned with `static_assert`s. ### Tested Linux (CachyOS, GCC): new `keyboard_input` test (`core/libs/prx/libSceKeyboard/tests/Keyboard.cpp`) passes. It drives `KeyboardInput` with synthetic SDL events (window filter, repeats, modifiers, LEDs, focus loss, disconnect, 16-key limit, history overflow) and checks the character table. It fails on each of three injected bugs (one table entry changed, keys kept on focus loss, no 16-key limit). Full suite: 90/90 pass. Windows only through CI. No title tested: no keyboard title available. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-01 17:01:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-01T17:01:10Z.


Progress report (bc51b33 → 63501b6)

📈 System libraries: 76.7% (+0.2%, +6 implemented functions)

✅ 6 implemented
Library Name
libSceKeyboard sceKeyboardClose
libSceKeyboard sceKeyboardGetKey2Char
libSceKeyboard sceKeyboardInit
libSceKeyboard sceKeyboardOpen
libSceKeyboard sceKeyboardRead
libSceKeyboard sceKeyboardReadState
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5936373179 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/225#issuecomment-5936373179). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-01T17:01:10Z. --- <!-- progress-report --> ### Progress report (bc51b33 → 63501b6) 📈 **System libraries**: 76.7% (+0.2%, +6 implemented functions) <details> <summary>✅ 6 implemented</summary> | Library | Name | | - | - | | libSceKeyboard | `sceKeyboardClose` | | libSceKeyboard | `sceKeyboardGetKey2Char` | | libSceKeyboard | `sceKeyboardInit` | | libSceKeyboard | `sceKeyboardOpen` | | libSceKeyboard | `sceKeyboardRead` | | libSceKeyboard | `sceKeyboardReadState` | </details>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!225
No description provided.