ChatGPT解决这个技术问题 Extra ChatGPT

Not able to type in textfield in iphone simulator using Mac Keyboard?

I'm working on a basic iOS app which supports both portrait and landscape modes. When the iPhone simulator keyboard is open in landscape and I'm switching the app to portrait mode I'm unable to type anything in any text field using my Mac physical keyboard.

Has anyone experienced this before? Is it a known bug?

Can you give more information such as the version of XCode and the iOS SDK that you are using please?
I have the exact same issue. I also sometimes get a long serious of invalid context warnings in the console.
None of these are working for me with Xcode 12.3.

S
Seto

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

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


this worked as in 2020...Couldn't type on simulator, after switching to Hardrware keyboard it works
The options path now is I/O >> Keyboard
P
Paulo Mattos

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

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

https://i.stack.imgur.com/c2kFY.png


Thanks. This is the only thing to work for me in Xcode 9. Had tried the various combinations inside the hardware menu to no avail. Went through and manually added it to all my sims. Did not destroy and recreate a sim yet to see if that also solved it. Not the first time apple has screwed up the sims, probably wont be the last either. :)
You deserve a medal.
This is the only fix that helped me. Thank you!
what an answer bro, hats off you
Yep, this is the answer for me. Thanks a lot
M
Meseery

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

OR

just press ⌘ + ⌂ + K


this worked for me, but just after I restarted the simulator
E
Eugene Osovetsky

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.


This answer is visible in a Google search for the problem. Well done, Eugene. How did you figure it out? Much better than the other "solutions" I've tried.
Typing CMD+Shift+K twice while the keyboard is appearing, solved the matter for me.
Doesn't work in simulator from Xcode 9. Nothing happens.
Worked for me once. Then keyboard stopped working for me again not too long after and now this doesn't work. (Simulator v10.0, Xcode 9.2)
A
Attila H

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)


P
PeqNP

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


Goofy. Worked for me.
If you've tried toggling the keyboard with shift-command-k then try this next.
@KeithTheBiped i tried shift-command-k with no luck before end up with restart ios simulator.
c
clopez

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 didn't have to do the first step, but the second step worked. Thanks!
I love how just about every answer to this question is completely different. Silly iOS simulator. Yours worked for me - I randomed it into submission :)
This worked for me, except I didn't need to bring up another simulator. I simply closed the window for the simulator (you can have multiple simulator windows up now, and close them individually too) and then re-ran app from Xcode to bring it back up. Definitely something flaky with the simulator. It's been problematic for a long time now :(
F
Fansad PP

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

https://i.stack.imgur.com/iVpgG.png


S
Simon Guest

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.


D
Dhaval H. Nena

Repeating below command twice worked for me!!

CMD+Shift+K


T
Tarun Seera

CMD + SHIFT + K

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


M
Muhammad Zeeshan

Its not a problem just Do these easy steps.

Open Simulator Going To Top And you See Option Hardware click on this. When you click on Hardware some option appear and one option is Keyboard. Click on the Keyboard option and you see three option appear. If you want to use your mac button keyboard simple select 2nd option Connect Hardware Keyboard. If your want to use mobile tapping keyboard select 3rd option. 1st option is for those who select their keyboard through code.

Enjoy that all work.


If it doesn't work. Kill(close and start) the simulator and repeat these steps again. Hope it will work.
p
pkamb

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.


V
Vikash Sinha

I just quit my simulator and it worked for me.


Lol! Perfect. Brilliant. I'm trying this and that. Finally I see your post, restart it and whalla!
M
Muhammad Asad

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

It worked for me.


A
Antonio MG

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/


A
Ashok R

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


M
Mostafa ElShazly

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

or alt-command-k


k
kakashy

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.


R
Rohan Sanap

Quit simulator and run following command in terminal:

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


perfect this answer!
d
dru

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!?


V
Ved Rauniyar

I just restart the simulator and It worked for me.


U
Uchenna Nnodim

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


A
Azules

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.


E
Easwaramoorthy K

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


A
Alvin George

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.


B
Benedict Cohen

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.


c
crypt

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.


P
Preetham NT

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


t
tyler hackett

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.