Get textarea selectionStart and selectionEnd

I’m attempting to insert a tab character when the tab key is pressed in a text area.

I’ve tried a few examples on line and could not get it to work.

The examples I’ve found reference selectionStart and selectionEnd to do this and last I checked these weren’t supported.