不能在 iphone 模拟器中使用 Mac 键盘输入文本字段?

我正在开发一个基本的 iOS 应用程序,它支持 都有的肖像和风景模式。当 iPhone 模拟器键盘在横向打开时,我将应用程序切换到纵向模式,使用我的 Mac 物理键盘,我无法在任何文本字段中输入任何内容。

以前有人经历过这种情况吗? 这是一种已知的病毒吗?

75208 次浏览

I just tried what you just said and it's true, it doesn't work if I move it to landscape and then to portrait again. It doesn't have any logic because my app is not even changing, and it works fine in the device, so it's a bug in the simulator.

You can report it to Apple using this:

https://developer.apple.com/bug-reporting/

I am seeing the same problem. I believe the issue is related to the command key being "stuck" in the simulator if you rotate the device in the simulator using Command-LeftArrow and Command-RightArrow short cuts.

While we wait for Apple to fix, one way around this is to rotate the device by selecting the menu option instead of the keyboard shortcut. This rotates the device, and seems to leave the keyboard in a working state.

Before you start typing (when the on-screen keyboard shows up), press just the command key by itself and then release it. This should re-enable the keyboard in the simulator.

On the Simulator try to change the device. Then run your app again on the original device. That worked for me.

If the first step alone doesn't work uncheck the option: iOS Uses same keyboard layout as OS X and then change the device.

I figured it out doing random stuff until it worked. Monkey fixing.

I have just installed a new version of Xcode (5.0) and the keyboard in iOS Simulator didn't work on first launch. Just restarting the Simulator helped.

None of these suggestions worked for me. I closed the iOS Simulator app and restarted it. That fixed it for me.

Launch iOS Simulator and enable Hardware > Keyboard > Connect Hardware Keyboard.

(You might have accidentally disabled it by pressing CMD + SHIFT + K - same shortcut as Clean in Xcode)

Found a great solution that worked for me.
Open simulator, then find menu Hardware -> Keyboard has three options:

  1. iOS uses same layout as OS X : This option disables the Mac keyboard
  2. Connect Hardware Keyboard : This option enables Mac keyboard but the keyboard will not show up.
  3. Toggle Software keyboard : This option will allow you type using your Mac keypad and will show the iOS on screen keyboard as well.

For me, Select Simulator, Select Hardware -> Keyboard -> Connect hardware Keyboard.

It worked for me.

I met this problem whenever I rotate the simulator. Following the suggestions to change Hardware options does not work for me, neither reboot iOS Simulator.

I found a trick that click the editing area after rotation makes Mac keyboard end up work.

From Simulator menu >> Hardware >> Keyboard >> Connect Hardware keyboard

OR

just press ⌘ + ⌂ + K

Its not a problem just Do these easy steps.

  1. Open Simulator

  2. Going To Top And you See Option Hardware click on this.

  3. When you click on Hardware some option appear and one option is Keyboard.

  4. Click on the Keyboard option and you see three option appear.

  5. If you want to use your mac button keyboard simple select 2nd option Connect Hardware Keyboard.

  6. If your want to use mobile tapping keyboard select 3rd option.

  7. 1st option is for those who select their keyboard through code.

Enjoy that all work.

In Xcode 9 I faced the same problem with the iPhone 8+ simulator. I was able to solve it this way:

  1. Open ~/Library/Preferences/com.apple.iphonesimulator.plist file
  2. Find the problematic simulator identifier (shown in the Devices and Simulator window)
  3. Set CaptureKeyboardInput value to YES
  4. Restart the Simulator

The solution that really work for me, was deleted the simulator and create new one. This bug I think that commonly occur when all shortcuts does not work from your keyboard to simulator.

After doing so many stuffs, just a restart of my machine and enabling the below worked.

Enabling this in simulator: Hardware -> Keyboard -> Connect Hardware Keyboard

For Version 10.0 (SimulatorApp-851.2 CoreSimulator-518.19) with Xcode 9.3, nothing worked for me. I reset the simulator by Hardware -> Erase All Content and Settings -> Erase. Cleaned the project and run on simulator. Keyboard connection is back.

If your Mac keyboard is still disconnected after having all the options and settings correct, one cause is from rotating the device.

If you CMD + or to rotate device early when the simulator is starting up, the Mac keyboard will absolutely not work no matter what; changing menu settings does nothing! It might help to use the Mac keyboard to input inside the device before you rotate device.

Turning off "Send Menu Shortcuts to Device" and restarting the Simulator helps sometimes. I'll update if I get reliable, recreateable behavior.

I find the Mac keyboard works about half the time I run and quit Simulator. 50% ain't bad after all these years!?

I ran into this problem after I removed Main.storyboard and created the main window in code. Reverting back to using Main.storyboard fixed it for me.

For me doing this worked on iPhone 8+ simulator iOS 11.2: 1. Go to Menu -> Hardware -> Erase all contents and settings. 2. Delete derived data from xcode. Xcode -> Preferences -> Locations -> Click on right arrow on left side of "Advanced" button.

Repeating below command twice worked for me!!

CMD+Shift+K

Quit simulator and run following command in terminal:

rm ~/Library/Preferences/com.apple.iphonesimulator.plist

I just restart the simulator and It worked for me.

Just use CMD+SHIFT+K and the keyboard will activate on it's own.

for me, on simulator opened, in the menu of your mac, click Hardware and reach to keyboard option and select toggle software keyboard.as shown

i think it is only because of a problem that you did not selected 'connect hardware keyboard option, on the simulator menu bar named 'Hardware'

Please follow the steps

Goto : Hardware -> Keyboard -> Connect Hardware Keyboard

Hope it will help you with the problem , Thank you.enter image description here

There is a library for editing plist files called plistlib. Here is my code:

    import plistlib


file_name = ('path/to/com.apple.iphonesimulator.plist')
try:
p = plistlib.readPlist(file_name)
p["ConnectHardwareKeyboard"] = "NO"
plistlib.writePlist(p, file_name)
except:
print("Failure")

This reads the plist file, changes the ConnectHardwareKeyboard value to No and then writes the new file to the same location. This works for me, but let me know if there is a better way to do it. I'm still new at coding.

I had problem with iPhone6 simulator i changed it to iPhone7.On iPhone7 i am able to continue my work.

I just quit my simulator and it worked for me.

CMD + SHIFT + K

I have pressed this command 2 times to toggle and then it started working

XCode 12/13: In the simulator window, from the top pane, I/O>Input>Send Keyboard Input to Device

or alt-command-k

For me this problem were coming by window initialisation from the SceneDelegate

in XCode 12, swift 5, minimum deployment target 14, Storyboard

I have used the code just same as below

 func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let _ = (scene as? UIWindowScene) else { return }
let windowScene = UIWindowScene(session: session, connectionOptions: connectionOptions)
self.window = UIWindow(windowScene: windowScene)
setRootVC()
}

After this code written I was getting this issue, paste is working but Keyboard not showing anyhow also not worked Mac Keyboard

to fix this I have removed these lines

 let windowScene = UIWindowScene(session: session, connectionOptions: connectionOptions)
self.window = UIWindow(windowScene: windowScene)

And the problem was fixed for me, now SceneDelegate looks like

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let _ = (scene as? UIWindowScene) else { return }
setRootVC()
}