How do I back up SMS without using (broken) touchscreen on Nexus 4? I have a rooted n4 with USB debugging enabled. The touchscreen is smashed, totally. There is an image on the screen, but it is not possible to enter any commands via the touchscreen. The device otherwise works normally. I can see what's on the screen, it connects to the wifi, etc.

So, for example Ritesh SMS backup won't work, because it needs me to tap commands on the phone. I tried the following solution
https://stackoverflow.com/questions/12266374/backup-full-sms-mms-contents-via-adb

but it won't work because the phone pops up saying 'do you want to give adb shell su permissions', I can't tap yes as I can't tap anything...
Note for Non-Nexus 4 users: if your device supports OTG, buy an OTG cable (comes very cheap) connect  a standard PC mouse  and the device to it and use the mouse to navigate the device. 



Since the USB debugging is enabled and authorized, you can make good use of KeyEvents. Use input command to simulate up, down, left, and right navigational turns and enter. 

Command: 

adb shell input keyevent KEYCODE          # adb shell input: give further options


Examples: 


adb shell input keyevent 22                # navigates one block rightward
adb shell input keyevent KEYCODE_DPAD_DOWN # navigates one block downward
adb shell input keyevent DPAD_LEFT         # navigates one block leftward


Relevant key codes:


19 -->  "KEYCODE_DPAD_UP" 
20 -->  "KEYCODE_DPAD_DOWN" 
21 -->  "KEYCODE_DPAD_LEFT" 
22 -->  "KEYCODE_DPAD_RIGHT"
23 -->  "KEYCODE_DPAD_CENTER"


(See more key codes here - by Rene Barbosa)

To simulate ENTER, use key code 66. 23 works too.

Use the key codes in combination. For example, when SuperSU app asks me to allow or deny root privileges to an app, I use the key codes 19, 20, 22 and 66 to simulate a tap on OK.



You can always use adb shell input tap X Y but you need the correct X and Y coordinates for the tap. You'll have to enable Pointer location under Developer settings as first step. Since the touchscreen is not working, finding the right coordinates is a hit and miss here. You would succeed with trial and error, should you choose this method.