Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Determine Text Cursor Position in Windows

Tags:

winapi

ime

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.

like image 204
dparakh Avatar asked Feb 23 '11 05:02

dparakh


People also ask

How do I find the cursor position in text area?

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.

How can I see my cursor coordinates?

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.

How do I find the cursor position in Excel?

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.


1 Answers

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.

like image 200
Sertac Akyuz Avatar answered Oct 22 '22 22:10

Sertac Akyuz