Convert text to key presses I am a robot. I bought this keyboard because of its easy rectangular layout:

~`   !1   @2   #3   $4   %5   ^6   &amp;7   *8   (9   )0   _-   +=
tab  Qq   Ww   Ee   Rr   Tt   Yy   Uu   Ii   Oo   Pp   {[   }]    \|
     Aa   Ss   Dd   Ff   Gg   Hh   Jj   Kk   Ll   :;   "'   [-enter-]
          Zz   Xx   Cc   Vv   Bb   Nn   Mm   &lt;,   &gt;.   ?/
                         [========= space =========]


To print human text, I need to convert it to commands that my manipulators can interpret. My left manipulator hovers over the Shift key. My right manipulator, at the beginning, hovers over the ~ key. The commands that my manipulators understand are:

S      : press the shift key
s      : release the shift key
L      : move the right manipulator left by 1
R      : move the right manipulator right by 1
U      : move the right manipulator up by 1
D      : move the right manipulator down by 1
P      : press the key under the right manipulator
p      : release the key by the right manipulator


Write code to convert any ASCII message to a list of commands. The input can contain any number of the 95 printable ASCII characters; possibly also TAB and newline characters. The output should be the list of the commands to the manipulators.

So, for example, to type Hello World!, the commands are

SRRRRRRDDPp
sLLLUPp
RRRRRRDPp
Pp
UPp
LLLLDDDPp
SLLLUUUPp
sRRRRRRRPp
LLLLLPp
RRRRRDPp
LLLLLLPp
SLLUUPp


I reset the manipulators to initial state before printing each message.

There are some mechanical hazards that should be avoided by proper programming:


No moving (LRUD) allowed when printing (P) is engaged
No jamming of manipulators: when a manipulator is engaged (S or P), the next command for this manipulator should be disengaging (s or p), and vice-versa
No unnecessary shifting: between each two shift (s, S) commands, there should be a P command

So, to print ~~, commands SPpPp are valid, while SPpsSPp are not
No moving out of bounds: no movement command should try to move the right manipulator more than 13 spaces to the right or 4 to the bottom of the initial position (or any spot to the top or left)


Additional notes:


Pressing a disabled key (command sequence like DDPp) results in no keys pressed and is allowed.
Pressing Shift+Tab has no effect, but Shift+Space and Shift+Enter have the same effect as without Shift.
Pressing on any spot on the space bar and the Enter key has the same effect.
Whitespace keys in output have no meaning, but can be used to format it in a beautiful way.
Python 2, 338 337 335 331 325 bytes



x=y=s=0
for c in input():p='`1234567890-=`&#9;qwertyuiop[]|`asdfghjkl;\'\n```zxcvbnm,./``````` ~!@#$%^&amp;*()_+~~QWERTYUIOP{}\\~ASDFGHJKL:"\n~~~ZXCVBNM&lt;&gt;?~~~~~~~ '.find(c);S=[p&gt;61,s][c in' \n'];p%=62;Y=p/14;X=[max(x,12),min(max(x,5),10),p%14]['\n '.find(c)];print'sS'[S]*(s^S)+'LR'[X&gt;x]*abs(X-x)+'UD'[Y&gt;y]*abs(Y-y)+'Pp';x,y,s=X,Y,S


Try it online!



Moves directly from each character to the next.

Explanation:


S=[c in K,s][c in' \n'], checks if the next character should be Upper- or lowercase. If c is a space or newline, the case remains the same.
X=[max(x,12),min(max(x,5),10),p%15]['\n '.find(c)]. If c is a space or newline, the closest x-coordinate to the current is chosen(as the keys span multiple columns)
print'sS'[S]*(s!=S)+'LR'[X&gt;x]*abs(X-x)+'UD'[Y&gt;y]*abs(Y-y)+'Pp', prints the case switch, the number of x-coordinate moves, the number of y-coordinate moves, and finally Pp, for each character




Shorter version, if the shortest path is not required:

Python 2, 294 293 291 287 281 bytes



x=y=s=0
for c in input():p='`1234567890-=`&#9;qwertyuiop[]|`asdfghjkl;\'\n```zxcvbnm,./``````` ~!@#$%^&amp;*()_+~~QWERTYUIOP{}\\~ASDFGHJKL:"\n~~~ZXCVBNM&lt;&gt;?~~~~~~~ '.find(c);S=[p&gt;61,s][c in' \n'];p%=62;X,Y=p%14,p/14;print'sS'[S]*(s^S)+'LR'[X&gt;x]*abs(X-x)+'UD'[Y&gt;y]*abs(Y-y)+'Pp';x,y,s=X,Y,S


Try it online!