Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Get the position of the cursor where I am writing on the screen



Permlink Replies: 4 - Last Post: Dec 27, 2016 7:57 AM Last Post By: Shlomo Abuisak
AskDesign Team

Posts: 1
Registered: 1/26/17
Get the position of the cursor where I am writing on the screen
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 26, 2016 2:39 PM
Hello

-I would like to know, is it possible with Delphi to get the position of the cursor CrlBeam (where I am writing on the screen) for external application

-For exemple if I am going to write on NotePad++, it will detect the position on the screen exactly where I am writing

image exemple: http://askdesigngroup.com/detect.jpg

My objective is to display a small suggestion Form down of the edit cursor

image objective: http://askdesigngroup.com/objectif.jpg

thank you for helping me :) :)

Edited by: AskDesign Team on Dec 26, 2016 2:40 PM

Carl-Henrik Nil...

Posts: 53
Registered: 3/26/02
Re: Get the position of the cursor where I am writing on the screen
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 27, 2016 1:02 AM   in response to: AskDesign Team in response to: AskDesign Team
AskDesign Team wrote:
Hello

-I would like to know, is it possible with Delphi to get the position of the cursor CrlBeam (where I am writing on the screen) for external application
-For exemple if I am going to write on NotePad++, it will detect the position on the screen exactly where I am writing
image exemple: http://askdesigngroup.com/detect.jpg
My objective is to display a small suggestion Form down of the edit cursor
image objective: http://askdesigngroup.com/objectif.jpg
thank you for helping me :) :)

The Windiws term for the blinking cursor is 'Caret'.
You can, for instance, play with these Windows functions:

GetCaretPos
WindowFromPoint
ClientToTcreen
--
C-H
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: Get the position of the cursor where I am writing on the screen [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 27, 2016 1:06 AM   in response to: AskDesign Team in response to: AskDesign Team
AskDesign Team wrote:

Hello

-I would like to know, is it possible with Delphi to get the position
of the cursor CrlBeam (where I am writing on the screen) for external
application

-For exemple if I am going to write on NotePad++, it will detect the
position on the screen exactly where I am writing

image exemple: http://askdesigngroup.com/detect.jpg

The insertion mark (called a caret, by the way) in a text editor may be
something the editor in question implements itself, not something drawn
by Windows. If this is the case (e.g in an application like MS Word)
you only have a chance to do what you want if the application offers an
API of some kind to interact with it.

For the caret build into standard edit controls (TEdit, TMemo in
Delphi) or created by a call to the CreateCaret API function the
Windows API has a function GetCaretPos, but the problem (for you) is
that this function only returns the (last) position of a caret inside
the application that calls it. You cannot get the position of the caret
in another application this way, nor can you get the handle of the
window with focus (which usually owns the caret) if the focus is in
another application. You would need that to convert the coordinates
returned by GetCaretPos (which are client coordiantes) to screen
coordinates to position you window.

So, the scheme can only work if you can inject code into the target
process, and the only way to do that in a way that will not require
elevated privileges or make any virus scanner howl in protest is to
use an API provided by the target application to load an extension DLL.
If said target application has no such API your objective cannot be
realized.

--
Peter Below
TeamB
Carl-Henrik Nil...

Posts: 53
Registered: 3/26/02
Re: Get the position of the cursor where I am writing on the screen [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 27, 2016 2:02 AM   in response to: Peter Below in response to: Peter Below
Peter Below wrote:
AskDesign Team wrote:

Hello

-I would like to know, is it possible with Delphi to get the position
of the cursor CrlBeam (where I am writing on the screen) for external
application

-For exemple if I am going to write on NotePad++, it will detect the
position on the screen exactly where I am writing

image exemple: http://askdesigngroup.com/detect.jpg

The insertion mark (called a caret, by the way) in a text editor may be
something the editor in question implements itself, not something drawn
by Windows. If this is the case (e.g in an application like MS Word)
you only have a chance to do what you want if the application offers an
API of some kind to interact with it.

For the caret build into standard edit controls (TEdit, TMemo in
Delphi) or created by a call to the CreateCaret API function the
Windows API has a function GetCaretPos, but the problem (for you) is
that this function only returns the (last) position of a caret inside
the application that calls it. You cannot get the position of the caret
in another application this way, nor can you get the handle of the
window with focus (which usually owns the caret) if the focus is in
another application. You would need that to convert the coordinates
returned by GetCaretPos (which are client coordiantes) to screen
coordinates to position you window.

So, the scheme can only work if you can inject code into the target
process, and the only way to do that in a way that will not require
elevated privileges or make any virus scanner howl in protest is to
use an API provided by the target application to load an extension DLL.
If said target application has no such API your objective cannot be
realized.

--
Peter Below
TeamB

Oh yes, you are so right. I totally missed the 'external application' part.
--
C-H
Shlomo Abuisak

Posts: 100
Registered: 9/18/10
Re: Get the position of the cursor where I am writing on the screen [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 27, 2016 7:57 AM   in response to: AskDesign Team in response to: AskDesign Team
On 27/12/2016 00:44, AskDesign Team wrote:
Hello

-I would like to know, is it possible with Delphi to get the position of the cursor CrlBeam (where I am writing on the screen) for external application

-For exemple if I am going to write on NotePad++, it will detect the position on the screen exactly where I am writing

image exemple: http://askdesigngroup.com/detect.jpg

My objective is to display a small suggestion Form down of the edit cursor

image objective: http://askdesigngroup.com/objectif.jpg

thank you for helping me :) :)

Edited by: AskDesign Team on Dec 26, 2016 2:40 PM

No need for position.
Use SendKey32
http://delphi.about.com/od/adptips2004/a/bltip1104_3.htm
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02