Yea, you can do this.  I do it when I am on a long car trip.   I use a USB female to USB micro male.  you hook the normal usb cord into the female end, and then plug the male end into the phone.
Alternatively, you could just get a USB micro/mini male to USB micro male and plug that directly into into your keyboard.