MBP 2013 keyboard & trackpad freeze after USB disconnect while sleeping MacBook Pro 2013 retina. Sometimes I plug my phone into one of the USB ports to charge it. Sometimes I close the MBP and let the phone keep charging. Sometimes I then unplug the phone without waking up the MBP. Sometimes (not always -- just intermittently) when I do open the MBP again after this sequence, the keyboard and trackpad no longer work. An external mouse still works fine. But no combination of switching plugs, re-attaching the phone, sleep/wake, will get me the use of the keyboard again. I'm stuck at the screen saver login page with nothing but an external mouse (can't type password, no option to shut down cleanly). I have to force shutdown by holding down the power button, which is not ideal.

Does anybody know a way to un-wedge at this point or re-enable the trackpad + keyboard? I'd love to be able to just get back to work again, or at the very least do a clean logout and shutdown without a force reset.
Workaround

When you find yourself in this situation, you should be able to just briefly press the power button. Just a quick half-second press. In doing so you'll be prompted to restart, shutdown, etc.

Potential fix

It may be worth you resetting the System Management Controller (SMC) to see whether this resolves the issue in the longer term.

To do this on your model of MBP, follow these steps:


Shut down your MBP
Keep the MagSafe adapter (power cable) plugged in.
Press at the same time shiftoptioncontrol (on the left side of the built-in keyboard) and the power button
Let go
Turn your computer back on with the power button.


Some tests

Have you tested to see whether this behaviour is replicated on all USB ports?

Another test would be to boot into Safe Mode and see if it is replicated, either during Safe Mode or again afterwards. I understand it's an intermittent issue, so these sorts of tests will require determination/patience.

To boot into Safe Mode:


Fully shut down your Mac
Restart your Mac
Immediately press the Shift key and keep it down 
Let go of the Shift key when you see the login window (NOTE: If you have FileVault enabled you may need to log in twice).
Try testing for the same behaviour
Exit Safe Mode by restarting your Mac as normal