Repository navigation
Type idb ui text on the simulator's hardware keyboard layout - #1002
Open
joshuayoes wants to merge 2 commits into
Open
joshuayoes wants to merge 2 commits into
joshuayoes wants to merge 2 commits into
Conversation
…ontrol SimulatorHIDEvent key presses are USB HID usages, which name key positions. The helpers that turn text into key presses map characters to positions with a US table, so on a simulator whose hardware keyboard layout is not US the guest types different characters: "azerty" arrives as "qwerty" on French. Add framework support for typing text on a given layout: - SimulatorHIDEvent.text(_:layout:table:) builds the key presses for a string from a layout table, resolving every character before any event is built. - SimulatorUSKeyboardLayoutTable is the US table that was private to the REPL's command dispatcher. - SimulatorUCHRKeyboardLayoutTable reads every other layout from the runtime's USBKeyboardLayouts.bundle and confirms the planned key presses with UCKeyTranslate. - Simulator.keyboard.typingEvent(for:layout:) types on a named layout, or on the one the simulator's keyboard settings give a newly launched app. The REPL's text command now goes through this. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`idb ui text` maps each character to a key position with a US table in the client, so a simulator whose hardware keyboard layout is not US types different characters: "mobiletest@example.com" arrives as ",obiletest2exq,ple:co," on French. HIDEvent gains a text event carrying the text and an optional layout name. The companion turns it into key presses for the simulator's layout and advertises support as CompanionInfo.hid_text. The client sends it to companions that advertise it and falls back to US key presses otherwise. `idb ui text --layout LAYOUT` names a layout explicitly; `--layout US` sends the key presses sent before this change. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
idb ui textmaps each character to a key position with a US table in the client and sends key presses. On a simulator whose hardware keyboard layout is not US the guest types different characters:idb ui text mobiletest@example.comarrives as,obiletest2exq,ple:co,on French, and characters off the US keyboard fail with "No keycode found". See #666.What changes:
HIDEventgains atextevent (HIDText: the text and an optional layout name). The companion turns it into key presses for the layout withSimulator.keyboard.typingEvent(added in the framework pull request this depends on).CompanionInfo.hid_text(field 13).Client.text(text, layout=None)sends oneHIDTextevent to a companion that advertises it.idb ui text TEXT --layout LAYOUTnames a layout to type on, such asUSorFrench. Without it the companion uses the simulator's own.INVALID_ARGUMENTbefore anything is typed. The message names the character's offset and the layout.Compatibility:
hid_textis absent, so the client sends the same US key presses it always has. A--layoutother thanUSis refused in the client before any event is sent.--layout USsends the key pressesidb ui textsent before this change, on any simulator, for every character the US table has.--layout USrestores the old behaviour.Known limit: an app keeps the hardware layout it was launched with. The layout is read from the simulator's keyboard settings, so after changing the simulator's keyboards either relaunch the app or pass
--layout.The
hidstream handler now resolves the first event of a stream before taking the HID lease, so reading the simulator's keyboard settings does not hold up other HID streams.Test Plan
./build.sh test CompanionTests: 225 tests pass../build.sh test CompanionLibTests: 163 pass../build.sh test FBSimulatorControlUnitTests: 513 pass../build.sh build allsucceeds.pip install ., thenpython -m pytest --pyargs idb -o python_files='*_tests.py'from outside the checkout): 411 passed, 1 skipped. Run on Python 3.14.idb/grpc/testsis not part of the installed package, so CI does not collect it. Run against a copy of the installed package: 216 passed, 1 failed. The failure isrepl_contract_tests, which could not load its fixture in that layout and is not touched by this change.test_ui_text_types_on_the_simulators_keyboard_layoutinEndToEndTests/test_accessibility.pypassed on fresh iOS 27.2 and iOS 26.2 simulators (run before rebasing onto 60beb1c; the before/after below was rerun after). It sets the simulator to French, types text that AZERTY moves along with option-layer and dead-key characters, checks a refused character types nothing, and checks--layout USsends US positions. It restores the keyboard settings it changes.hw=Automatic, German, Canadian French and Devanagari strings typed exactly, includingmobiletest@example.com,€,ê,ñ,ß.café €typed exactly.--layout US:azertyarrives asqwerty.abc日def: exit 1,Cannot type the character at offset 3 on the French hardware keyboard layout, field unchanged.--layout Bogus: exit 1,The simulator's runtime has no hardware keyboard layout named "Bogus", field unchanged.,obiletest2exq,ple:co,formobiletest@example.com; this change types it exactly. Recording (stock idb first, then this change):proof.mp4
--layout FrenchwithThe companion does not support typing on a keyboard layout; a 1.7.6 client against this companion behaves as before.python -m CI.check_documentation_linkspasses.Related PRs
Depends on #1001. Until that lands this branch carries its commit too, so only the second commit is new here.
website/docs/idb/ui.mdxandcommands.mdxare updated in this pull request.🤖 Generated with Claude Code