Were you using a 3rd party keyboard? It's still weird because if you did, the 'stock' keyboard should have taken over... but if you rooted your phone and deleted the keyboard files, then your only option at this point, I think, would be to connect a previously-paired Bluetooth keyboard with the phone or using an USB one if the M2 supports OTG Cables (not sure).
If the problem was with a 3rd party keyboard and not a rooted phone, you might try to boot into Safe Mode.
To enter safe mode and remove a malicious app:
With the smartphone turned on, press and hold the "Power" button
Tap and hold "Power off"
In the Safe Mode prompt, tap "OK". Your smartphone will reboot in safe mode
After the device reboots, the "Safe Mode" label should be present on the screen
To uninstall an app, tap the "Applications" icon while on the home screen
Tap "Settings"
Under "Device", tap "Apps"
Swipe to the "Downloaded" screen
Select the desired application and tap "Uninstall"
Tap "OK" to confirm
To exit safe mode, press and hold the "Power" button > tap "Power off"
Once the smartphone is turned off, press and hold the "Power" button to reboot your device as you normally would
(Taken from
How-to: Sony Xperia M2: Clear the Cache Partition and Rebooting in Safe Mode)