Greetings shivangi_dh,
Thanks for reaching out to the Apple Support Communities! It sounds like you have an issue connecting an external keyboard to your MacBook Pro.
"First, check your device's USB connection. If the tips on that page don't fix it, try these steps:
- Unplug all devices from your computer, including any connected mouse, keyboard, printer, scanner, camera, iPod, external hard drive, and hub.
- Some devices, like iPod, might require you to perform steps before it's safe to unplug them.
- Plug your keyboard and mouse back into your computer firmly and securely. Make sure that the connector is completely in the port. (USB plugs fit into ports one way only, and won't plug in if you try to insert them upside-down.)
- If you have a Magic Keyboard or Magic Keyboard with Numeric Keypad, also make sure that your Lightning to USB cable is securely connected to the Lightning port on the back edge of the keyboard.
- If your keys still don't work, try plugging your keyboard in to the other USB ports. Be sure to try them all. Check to see if the keyboard's Caps Lock light turns on when you press it, and try typing in an app like Notes or TextEdit.
- Magic Keyboard and Magic Keyboard with Numeric Keypad use a Lightning to USB cable. Make sure that the cable you're using is the one that came with the keyboard, or is a Lightning to USB cable that you know is in working order. You can try a different Lightning to USB cable to test whether the cable is causing the issue.
Other tips for fixing issues with your USB keyboard:
The above information was taken directly from the following resource.
Cheers!