What is the best way to determine the screen co-ordinates of the currently active text input cursor?
I need this for an in-line transliteration program so that I can display some suggestions options to the user as the text is entered.
First, get the current position of cursor with the help of property named as selectionStart on textarea/inputbox. To insert the text at the given position we will use slice function to break the string into two parts and then we will append both parts to the text(text_to_insert) in front and end of the text.
In Mouse Properties, on the Pointer Options tab, at the bottom, select Show location of pointer when I press the CTRL key, and then select OK.
Click anywhere inside the text of the Get_Cursor_Pos routine and press the F5 key to run the Get_Cursor_Pos macro. You will get a message box displayed with the coordinates of the current position of the mouse pointer.
First attach the thread input to the active application (AttachThreadInput
). Then get the caret's position with GetCaretPos
. The position is in client coordinates, call GetFocus
to have the handle to the window that has the caret, then convert the coordinates to screen coordinates with ClientToScreen
. Finally detach the thread input by calling again AttachThreadInput
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With