It's tricky, because it's impossible to fully simulate a key event in general. Specifically, it's not possible in most browsers to trigger the default browser action for a key event without an actual keystroke having occurred.
That being the case, you have to do it manually, which is complicated. Arrow keys work on the visible text on the page, which means you need to take into account things like collapsed spaces, implied line breaks from <br>
and block elements, elements hidden via the CSS display
property and many other subtleties. Also, simulating up and down arrow keys relies on obtaining exact pixel co-ordinates of arbitrary characters on the page, which is non-trivial in most browsers.
I'm working on a means for navigating through the visible text on the page in Rangy, which will help with simulating left and right arrow keys, but Rangy can't help with up and down arrow keys.