WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Mouse and Cursor Topics

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How to Find the position of the Cursor/Caret
on the Screen (32-bit only)

Keywords:  cursor position caret position  

It's easy to get the mouse cursor position, (see example below) but it's not all that useful. What you probably *really* want is the position of the caret. That's usually the vertical line telling you where characters will go when you type.

The usual method is to set the caret where you want it (by some method - MouseClick maybe - good luck) and then proceed from there.

This script finds the position of the Cursor/Caret on the screen, but... beware... it doesn't really work (see caveat in question #2/answer below):

	;Get (useless) cursor position dllcall
	;this is for 32 bit Windows only, finds the position of the Cursor/Caret on the screen
	winactivate("~Notepad")
	delay(2)
	bb=binaryalloc(20)
	binaryeodset(bb,20)
	mydll=strcat(dirWindows(1),"user32.dll")
	err=dllcall(mydll,long:"GetCaretPos",lpbinary:bb)
	x=binarypeek4(bb,0)
	y=binarypeek4(bb,4)
	binaryfree(bb)
	display(5,"Cursor(Caret) Positions","Horizontal %x%%@CRLF%Vertical %Y%")
	;message("",err)  ;-------for debugging purposes

Question:

I am running a terminal emulation program under Windows 95 and would like to use Winbatch to help me with some automatic updates on the mainframe which I am attached to. I need to check my cursor position each time before I update a field. I have tried using the suggestions elsewhere in the tech support section, but have been unable to get them to work. The first one I tried, with no luck at all, was "DLLCall Set Cursor Position". The second one I tried was "Cursor(Caret) position on screen" (displayed above). This one seemed to run but alway returned "0,0" for a position . . . . . even if I was at position "5,8". Has anyone else found a workable solution for a problem like this?

Answer:

Well, we cannot "see" the caret (again, that's usually the vertical line telling you where characters will go when you type) in another application. So you do indeed get back 0,0.

Depending on your emulation program, it is usually better to directly use the API it supports. Most terminal emulation programs for mainframe access support EHLLAPI or subsets of it. Otherwise, you need to use the script language supported by your emulation program. If it have neither, your should consider getting a better emulation program!


Article ID:   W13295
Filename:   Find Cursor -Caret- position on screen.txt
File Created: 1999:04:15:16:53:04
Last Updated: 1999:04:15:16:53:04