Here, the ; marks a new command. The newline-insert newline does the trick of Enter. The cursor is moved by down and char-forward. Not used here, but available, are also up and char-backwards

(This is a cumbersome way of doing so, and could be replaced by command-sequence math-insert \sum\limits_{\substack{0<k<p\\\gcd\left( k,p\right) =1}}; char-forward; char-forward -- it is merely meant to illustrate the constructions used).

To produce just the sum with the two-rowed substack and the cursor in the top row, use

I'm not that familiar with LyX, but I think you have to add three new shortcuts to be able to add all of that using keyboard shortcuts only. If you do not know how to do this, see my answer to Shortcuts for Lemma, Claim, Theorem etc.

I added keyboard shortcuts for \substack, \gcd and \left( \right). The LyX functions (and keyboard shortcuts) I used were as follows. You can of course choose whichever keyboard shortcut that suits you and doesn't conflict with existing ones.

math-insert \substack

Ctrl+Alt+Shift+0

math-insert \gcd

Ctrl+Alt+Shift+G

math-insert \left( \right)

Ctrl+Alt+Shift+P

The sequence for inputting your example will then be as follows, assuming you are in math mode:

Alt+MU - enters summation sign

Alt+MX - adds subscript

Alt+ML - adds \limits

Ctrl+Alt+Shift+0 - see above, begins a \substack.

0<k<p

Ctrl+Enter - starts a new line in the substack ...

↓ - ... but doesn't move the cursor it seems.

Ctrl+Alt+Shift+G - see above, enters \gcd

Ctrl+Alt+Shift+P - see above, enters \left( \right)

(these two can be done as one, hold down the modifiers and hit G followed by P)