ChatGPT解决这个技术问题 Extra ChatGPT

How do I type using my keyboard on the iphone simulator?

I used to be able to type with my real mac keyboard after launching the iPhone Simulator. Typing with the on-screen simulator keyboard is just horrible when testing with large amounts of text.

No matter what I do, I can't get my keyboard to type anymore inside the simulator. Even if I have "Simulate Hardware Keyboard" switched ON, it just won't type anything. Can someone please tell me what I'm doing wrong? Is there no way to type using the real keyboard anymore?

@user189924: Please mark previous questions with accepted answers, where people helped you out. It helps the community and motivates others to answer your future questions.
All 5 of the current answers work, but the VERY BEST answer is the one currently at the bottom by @SGS.
Hi @strange – with xCode 6 onwards, the selected answer doesn't seem to be the best approach. Would you consider re-evaluating your choice? The two answers about using the simulator's menu options and covering the keyboard shortcuts are slamor's and my own. However, if you are happy with the current choice, please keep that one.
⇧⌘K as explained by @Benjohn stackoverflow.com/a/26715382/242933
Same thing happened to me and was solved this way- stackoverflow.com/a/47696048/413877

R
Raj Aryan

Try trashing the iPhone Simulator preferences file. When my iPhone Simulator stopped responding to keystrokes, this fixed it.

Quit the simulator. Go to finder and press (command+shift+G) then navigate ~/Library/Preferences. Move com.apple.iphonesimulator.plist to the trash. Try launching your iPhone app in the simulator again.


When I rotate or zoom, I lose the ability. Is there a permanent solution?
@Philosophistry I lose the ability to type too, when I rotate using ⌘→ or ⌘←. I found out that I need to rotate it using the menu entries.
There appears to be a bug in the simulator where it stops responding to the keyboard after using the rotate shortcuts. To fix this, tap the ⌘ Cmd key on its own. It should accept typing again. See also: stackoverflow.com/questions/18979510/…
Instead of deleting the plist file, I just open it and change the field EnableKeyboardSync to YES. Then I restart my simulator.
This answer is no longer correct as of XCode 6.0.1. See @slamor and Keith Smiley's answer below.
K
Keith Smiley

Deleting com.apple.iphonesimulator.plist did not help me under Xcode 6.0.1. Probably, it worked in old Xcode.

But, what works perfectly for me under Xcode 6.0.1, it is new hot Keys in iOS Simulator:

Shift-Command-K   Connect/Disconnect Hardware Keyboard
Command-K         Toggle (Show/Hide) Software Keyboard

And, you know, I really suffered for last 2 months, until found it, and it is very convenient now))


Thank you! I was struggling typing my loooong credentials into app like for a week! :)
You are welcome! By the way, these hot keys work perfectly also in the latest xCode 6.1 under OS X Yosemite.
Really Helpful, I too was struggling from couple of days.
This is a much better workaround to Apple's bug than the accepted answer.
this is the correct way, I was struggling for several days to make the simulator use the physical keyboard. I'm not sure if this is a bug, it might be a feature, from Apple point of view, to allow to swap between tap based input or external hardware
B
Benjohn

Don't trash the iPhone simulator preference files. There's no need to do this.

Look in the simulator's menu Hardware ➔ Keyboard. The menu options are:

iOS Uses Same Layout as OS X Connect Hardware Keyboard ⇧⌘K Toggle Software Keyboard ⌘K

Ensure option 2 is checked.

If it's already checked, uncheck it then check it again (you'll probably want to learn the keyboard shortcuts).

If you find that this hides the on screen keyboard, but you also want this to show, use option 3 to toggle it back on.

If rotating the simulator seems to stop the keyboard working, toggle option two off then back on – this seems to resolve it.


This worked for me! Definitely try this before throwing anything away
Almost two years on from answering, this being far and away my most up-voted answer on S.O., tells you everything you need to know about contemporary software engineering :-)
For some reason I had the same problem. My keyboard was working and at some point this setting has changed and keyboard in simulator stopped working. This is the answer that sovled my problem in XCode 8.3
@sonar0007 It frequently re-happens to me when I upgrade xCode.
s
shim

I am using iOS Simulator Version 7.0. While the simulator was running I went to iOS Simulator->Reset Contents and Settings... and reset the simulator from there. That seemed to have done the trick for me. Hope that helps.


It works for iOS7 but once you change window scale for simulator it again stops responding to hardware keyboard.
This is the best way to relaunch keyboard
On iOS Simulator 10.0 use Hardware -> Erase All Content and Settings...
B
Benjohn

This is because you have used changing the orientation of simulator using keyboard shortcuts. Just press cmd on the mac keyboard then start typing.


In my opinion this is the best answer.
That works about half of the time. That other half, something else caused it, and this doesn't do the trick.
I tried all of the above solutions, but typing cmd saved my day.
C
Chicowitz

All I needed to do was quit the simulator and launch it again


R
Ram Madhavan

MY PROBLEM WAS KEYBOARD IS SHOWING AND KEYSTROKES NOT DETECTING. AND I FOUND THE SOLUTION:

You don't need to quit the keyboard.

Try Hardware->Keyboard->Connect Hardware Keyboard directly


P
Praveenkumar

Removing com.apple.iphonesimulator.plist worked for me too, but I had to locate it inside the hidden folder /Users/[yourusername]/Library/Preferences/


Actually the tilde sign "~" in "~/Library/Preferences" translates to /Users/[yourusername] in the terminal, its just a convenient special character in unix paths for ones home directory.
E
Evgeny Faddeenkov

Shell / Command-Line / Jenkins / CI:

sh "plutil -replace DevicePreferences.${deviceID}.ConnectHardwareKeyboard -bool NO $HOME/Library/Preferences/com.apple.iphonesimulator.plist"
sh "plutil -extract DevicePreferences.${deviceID} xml1 -o - $HOME/Library/Preferences/com.apple.iphonesimulator.plist"

The Device ID can be found via xcrun / simctl, based on the devoce name:

xcrun simctl list | grep ${simulatorDeviceName} | sed 's/).*(.*//;s/.*(//'

C
Community

I encountered the same problem and tried a lot of different ways which worked mostly but never for sure. Ultimately, I found this. https://stackoverflow.com/a/26057011/1463604


F
Franz

If you are developing a React Native app and you cannot refresh (⌘R) or enable remote debugging (⌘D) from the iOS simulator, while other keyboard inputs work, make sure you are running a debug build configuration. You can check this with:

Product -> Scheme -> Edit Scheme -> Run -> Info -> Build Configuration -> Debug"

I got this tip from here.


D
Dmitry

Just restart Simulator (close and open the app).