How I can insert text at the current cursor position

I want to insert text at cursor position by click on a outside button but when click on the button the editor is not in focus so not able to find the cursor position so please give some solution for it?