Repository navigation
Type text on the simulator's hardware keyboard layout in FBSimulatorControl - #1001
Open
joshuayoes wants to merge 1 commit into
Open
joshuayoes wants to merge 1 commit into
joshuayoes wants to merge 1 commit 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>
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
SimulatorHIDEventkey presses are USB HID usages, which name key positions. The helpers that turn text into key presses (the REPL'stextcommand here, andidb ui textin the client) 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. See #666.This adds the framework support for typing text on a given layout:
SimulatorHIDEvent.text(_:layout:table:)builds the key presses for a string from a layout table. Every character is resolved before any event is built, so text with a character the layout has no key for throwsSimulatorHIDError.characterNotOnKeyboardLayoutand sends nothing. The error names the character's offset and the layout, not the character, so typed text stays out of logs.SimulatorUSKeyboardLayoutTableis the US table that was private to the REPL's command dispatcher. A test pins it entry by entry toKEY_MAPinidb/common/hid.py.SimulatorUCHRKeyboardLayoutTablereads every other layout from the runtime's ownUSBKeyboardLayouts.bundle, the data the guest types with, including option and dead-key sequences. The planned key presses are replayed throughUCKeyTranslateand refused if they would not reproduce the text.Simulator.keyboard.typingEvent(for:layout:)types on a named layout, or on the one the simulator's keyboard settings give a newly launched app (AppleKeyboards,AppleKeyboardsExpanded,KeyboardLastUsed, andAppleLanguageswhen the keyboards have not been written yet). A layout that cannot be determined is assumed to be US, and the reason is logged.The REPL's
textcommand now goes through this, so it follows the simulator's layout. On a simulator set to US it sends the same key presses as before for every character the US table has; characters outside that table that the runtime's US layout can type, such as "é", are now typed instead of refused.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 an app has to be relaunched before the two agree.
No change to
idb.proto, the gRPC server or the Python client.FBSimulatorControlnow importsCoreServicesforUCKeyTranslate. The Xcode build links it through autolinking; the generatedproject.ymlandLibraryPackage.jsondo not list it and I have not edited them.Test Plan
Run on this change alone:
./build.sh test FBSimulatorControlUnitTests: 513 tests in 70 suites pass. New suites:SimulatorUSKeyboardLayoutTableTests,SimulatorHIDEventTextTests,SimulatorKeyboardLayoutTests,SimulatorUCHRKeyMapTests../build.sh test CompanionLibTests: 163 tests in 27 suites pass../build.sh build idb_companionsucceeds.Run with the follow-up change applied as well:
./build.sh test FBSimulatorControlSmokeTestson fresh iOS 27.2 and iOS 26.2 simulators: 16 tests run, 0 failures (1 and 2 skipped; the skips are existing tests).SimulatorKeyboardSmokeTests(14 tests) loads every layout the runtime ships, checks French, German, Canadian French and US key presses against the runtime's data, and checks that the layout follows the simulator's keyboard settings.IDB.ui.text("azerty mobiletest@example.com €ê ñ^")into a text field arrives as that text../build.sh build allsucceeds.The unit, CompanionLib and build results are from
mainat 60beb1c with both changes applied. This change was built and tested alone, and the smoke tests were run, on 5f34870 before rebasing; the rebase touched none of these files beyond a clean merge inIDBCommandExecutor.swift.Related PRs
The gRPC event, the
idb ui text --layoutoption, the end-to-end test and the website docs follow in #1002, which builds on this one.FBSimulatorControl/README.mdis updated here.🤖 Generated with Claude Code