|
Dear Saurabh,
Your code works nicely in WinWord.But when you select some text, the caret disappeared and this code doesn't work anymore. Can I get the position where text is selected?
Dallas
|
|
|
|
|
I have been searching for solution, and Saurabh had explained it in excellent manner
|
|
|
|
|
Hello, I would like to know if you point me in the direction of Visual Basic Classic. Your exe works like a charm and exactly what I am looking for. Can you also "Set" the caret position?
|
|
|
|
|
Thanks for the project and code.
I was looking to achieve similar functionality and your project helped a lot. However, when testing the application I found that it worked on most open windows but not in all. It failed to get the caret position in Visual studio 2010 and failed in Firefox. It does, however, display the name of the open windows of these two but not the caret position.
I think it fails to get the caret position in Visual Studio 2010 because it is a WPF application. I don't know why it fails in Firefox. Any ideas on how to remedy this??
Again, many thanks.
|
|
|
|
|
WPF uses DirectX to render UI that's why caret is not accessible.
|
|
|
|
|
This is excellent. Keep up the good work.
Please I need code to extract the word from current caret position, in MS Word, NotePad, etc?
Also, is there a way to find which word the user has clicked in FireFox?
Thanks
|
|
|
|
|
It cannot provide 100 percent detection.
If the app implement their own caret mechanizm or if the owner of the caret is not the window in focus (which is implementation driven) then this solution will not work.
Try firefox or goole chrome for example.
|
|
|
|
|
|
Try firefox for example - they implement their own caret mechanism.
please advise.
|
|
|
|
|
Did you find any solution for this to work in Browsers ( chrome / firefox etc)
|
|
|
|
|
I was working on an autocomplete program where the autocomplete textbox follows
the caret with text to speech. With your help I was able to complete in one hour.
Thanks very much.
|
|
|
|
|
Hi there, I'm trying to do something very similar to this and will likely end up using much of this code. My problem, though, calls for variable content in the tooltip that follows the mouse cursor (something similar to Intillisense in VS, etc). Is there a way to expand this code easily to allow me to display my content?
Thanks
|
|
|
|
|
You can use keyborad hooking.
|
|
|
|
|
Saurabh,
First of all, thank you very much for your code contribution. You are really moving forward the art of UI interactivity. I was curious if you've given some thought to how this tool could be used within browsers. Currently, my experience is that the caret following stops whenever the caret is within a browser. Your thoughts?
Thanks again,
John Glosson
|
|
|
|
|
Hi John,
Have you managed to find a solution for web browsers?
Thanks
Lucien
|
|
|
|
|
Hi Saurabh,
This was a very good article and has helped me a lot. Thanks.
Satish
|
|
|
|
|
hi,
thanks for the code. how do i attach a tooltip to the caret?
|
|
|
|
|
I'm using voice recognition software, and I've written an AutoHotkey script to snap the mouse cursor to the text caret based on your code here. I had to write an exception for apps (e.g. Firefox) that sometimes report 0,0 for their caret location, but your contribution has made my life much more convenient.
Thank you kindly, ~Ivo
|
|
|
|
|
Could you please post the AutoHotKey script you wrote?
Thank you.
|
|
|
|
|
This script isn't as generalized as I'd like, but it should at least give you a decent example:
CoordMode, Mouse, Screen
CoordMode, Caret, Screen
CoordMode, ToolTip, Screen
SendEvent {Left} ; moving the caret helped on my machine, try removing this and the last line
; base for code at http:
NumPut(VarSetCapacity(gi,48,0),gi) ; set cbSize var in structure
hWnd:= WinGet,
tid := DllCall("GetWindowThreadProcessId", "Uint", hWnd, "Uint", 0)
DllCall("GetGUIThreadInfo", "Uint", tid, "Uint", &gi)
VarSetCapacity( xyPair, 8, 0 )
caretX := NumGet(gi,40) + 6
caretY := NumGet(gi,44) - 9
if( 20 > caretX or 20 > caretY ) ; top left corner if not found
{
ToolTip, cannot find text caret
SetTimer, ToolTipTimeOut, -2000
return
}
NumPut( caretX, xyPair ) ; get right and bottom coords of caret rect
NumPut( caretY, xyPair, 4 )
DllCall("ClientToScreen", "Uint", NumGet(gi, 28), "Uint", &xyPair)
caretX := NumGet(xyPair)
caretY := NumGet(xyPair, 4)
MouseMove, % NumGet(xyPair), % NumGet(xyPair, 4), 1
ToolTip, !, caretX, caretY, 2 ; make the new location more visible
SendEvent {Right} ; moving the cursor back to it's original position
Have fun, and let me know if you find bugs.
|
|
|
|
|
Thank you!
It works, if I take out all reference to ToolTip, i,e. CoordMode, ToolTip, {.. ToolTip... } and ToolTip,! parts. Otherwise, it generated an error message that the "Target Label Does Not Exist."
I don't need the message, just to move the mouse to the cursor, which this does.
modified on Friday, July 16, 2010 6:32 PM
|
|
|
|
|
*nods* My apologies about that, I simply forgot to take out my debugging code before I posted it. Would you be so kind as to upload your corrected version? If it's not convenient I can get to it soon-ish.
|
|
|
|
|
CoordMode, Mouse, Screen
CoordMode, Caret, Screen
SendEvent {Left} ; moving the caret helped on my machine, try removing this and the last line
NumPut(VarSetCapacity(gi,48,0),gi) ; set cbSize var in structure
hWnd:= WinGet,
tid := DllCall("GetWindowThreadProcessId", "Uint", hWnd, "Uint", 0)
DllCall("GetGUIThreadInfo", "Uint", tid, "Uint", &gi)
VarSetCapacity( xyPair, 8, 0 )
caretX := NumGet(gi,40) + 6
caretY := NumGet(gi,44) - 9
;if( 20 > caretX or 20 > caretY ) ; top left corner if not found
NumPut( caretX, xyPair ) ; get right and bottom coords of caret rect
NumPut( caretY, xyPair, 4 )
DllCall("ClientToScreen", "Uint", NumGet(gi, 28), "Uint", &xyPair)
caretX := NumGet(xyPair)
caretY := NumGet(xyPair, 4)
MouseMove, % NumGet(xyPair), % NumGet(xyPair, 4), 1
SendEvent {Right} ; moving the cursor back to it's original position
==EndCode==
I notice that even thought I commented out the line "if( 20 > ....", or if that line is deleted,
the mouse will move to the top left corner when the macro fails. Apparently, some programs don't have a "cursor" or "caret", even though there is an indicator in the programs as to what it is focused on. For example, PaperPort 11 can have a focus on a particular folder, and Quattro Pro on a particular cell, but the above macro has no effect but to jump the mouse to the top left corner of the screen.
Seems it would be better when the macro failed to leave the mouse where it is. How to do that?
|
|
|
|
|
Thanks for posting your version.
Regarding the mouse jumping into the corner, I've run into the same problems since I originally posted, and it doesn't <i>seem</i> to be a bug in the script. I've discontinued use of the function until I have time to figure out why that's happening and implement a fix... And that's probably not soon.
I suspect that the affected programs aren't using the operating system's text cursor, so the function that the script calls has no idea what the program in question is doing. I don't see any universal way around that, although under some circumstances you could find the control that currently has focus and center the mouse on that.
Sorry I couldn't help more, and I'd love to hear if you work out either of those issues.
|
|
|
|
|
We can add Firefox as a program that doesn't seem to allow script to see the text cursor, even though the cursor is visible while I write this email.
Couldn't one tell the script not to move the mouse if no cursor is found? It currently jumps to 6, 0 if no cursor is found.
|
|
|
|
|