Jump to content

Position of text cursor


Bert
 Share

Recommended Posts

Is it possible to see where the text cursor is? I'm not refering where the mouse pointer is, but the text cursor where the next letter that is typed will be shown?

I'm working with a IE window that I need to send text to, and I need to make sure the text cursor is in the right place. Due to windows changing sizes between users, I can't use a mouse pointer to do this. Also, trying to read the control in this IE window is about impossible. I ran AU3Record 3.1 to see what it could do, and this was the code it produced:

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
WinWait("Unicenter ServicePlus Service Desk - Incident Search","")
If Not WinActive("Unicenter ServicePlus Service Desk - Incident Search","") Then WinActivate("Unicenter ServicePlus Service Desk - Incident Search","")
WinWaitActive("Unicenter ServicePlus Service Desk - Incident Search","")
MouseMove(645,263)
MouseDown("left")
MouseUp("left")
Sleep(1000)

It went with mouse movements, which won't work for reasons I have explained above.

I tried to get information on the control I want to send text to by running Active Window info, and this is what I got:

CODE
>>>>>>>>>>>> Window Details <<<<<<<<<<<<<

Title: Unicenter ServicePlus Service Desk - Incident Search

Class: IEFrame

Size: X: 0 Y: 0 W: 1024 H: 691

>>>>>>>>>>> Mouse Details <<<<<<<<<<<

Client: X: 629 Y: 239

Cursor ID: 5

>>>>>>>>>>> Pixel Color Under Mouse <<<<<<<<<<<

RGB: Hex: 0xFFFF99 Dec: 16777113

>>>>>>>>>>> Control Under Mouse <<<<<<<<<<<

Size: X: 0 Y: 50 W: 1016 H: 594

Control ID:

ClassNameNN: Internet Explorer_Server1

Text:

Style: 0x56000000

ExStyle: 0x00000000

>>>>>>>>>>> Status Bar Text <<<<<<<<<<<

(1):

(2):

(3):

(4):

(5):

(6): Local intranet

>>>>>>>>>>> Visible Window Text <<<<<<<<<<<

Links

http://usdp/CAisd/pdmweb.exe

http://usdp/CAisd/pdmweb.exe

??

??

??

??

??

??

>>>>>>>>>>> Hidden Window Text <<<<<<<<<<<

??

I had the text cursor in the correct control when I did this capture.

I have a soluton that works 95% of the time, however, I wanted to make it bulletproof. When it fails, the text cursor will be in the 1st or 2nd field, instead of the third, causing the search to fail. This is due the window not fully being displayed. Due to the nature of the window, winwaitactivate doesn't always work, and using sleep statements either will cause long pauses, or the window gets missed, causing a failure. I tried going for a balance with both sleep statements and winwaitactive lines to minimize the failure rate.

I also added some Winactivate lines so if in case the user clicked a different window while the script was running, it would go back to the correct window. This improves the success rate.

The code I came up with to do this is this:

BlockInput(1)       send("!e")      sleep(3)        send("!i")    BlockInput(0)     WinActivate ( "Unicenter ServicePlus Service Desk" , "http://usdp/CAisd/pdmweb.exe" )       WinWaitActive( "Unicenter ServicePlus Service Desk" , "Opening", 1 )        sleep(300) ;script has much higher failures with this missing       WinActivate ( "Unicenter ServicePlus Service Desk" , "http://usdp/CAisd/pdmweb.exe" )       WInWaitActive( "Unicenter ServicePlus Service Desk" , "Done", 1 )       sleep(400) ;script has much higher failures with this missing       WinActivate ( "Unicenter ServicePlus Service Desk" , "http://usdp/CAisd/pdmweb.exe" )       BlockInput(1)       send("{TAB 2}")     $search1 = iniread("unplus.ini", "incident", "search", "")      WinActivate ( "Unicenter ServicePlus Service Desk" , "http://usdp/CAisd/pdmweb.exe" )       Send($search1)      WinActivate ( "Unicenter ServicePlus Service Desk" , "http://usdp/CAisd/pdmweb.exe" )       send("!s")      BlockInput(0)

Anyone got a better idea on to make this 100% foolproof? If not, I will go with what I got. I'm just trying to avoid users calling me saying it doesn't always work. :lmao:

Link to comment
Share on other sites

...Anyone got a better idea on to make this 100% foolproof?...

This suggestion will not be foolproof, but take a look at this rather long post:

http://www.autoitscript.com/forum/index.php?showtopic=14395

[using COM to get around within IE is so much better (or so Im told)...]

If you turn on the status bar within IE, manually surf to the page of interest and then manually tab thru all of the fields on that page - looking for changes in the status bar that your script can key from - then you "know where you are" and can tab backwards or forwards as needed to get to your starting place.

If there is not any unique status bar text, then try sending a control-F to the IE window of interest to do a "Find (on This Page)". Search for the text that identifies the field of interest. Once that text is "found", tab from there... but not all web pages let the tab order be influenced by such a search/highlight/tab.

Also, I noticed that you wait for "Opening" and then "Done" in the status bar. Does the status bar change back and forth between "Opening" and "Done" while loading? If so, I may have some code that can help with that - if I can find it.

Edit: To be clear, does the status bar indicate "Opening", "Done", "Opening", "Done", "Opening" .... and finally: "Done"?

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

cant you just get the source and work from that ?

Tried that. The program is written in a customized version of java, and runs in a IE window. I'm not allowed to look at the source code. ;)

If you turn on the status bar within IE, manually surf to the page of interest and then manually tab thru all of the fields on that page - looking for changes in the status bar that your script can key from - then you "know where you are" and can tab backwards or forwards as needed to get to your starting place.

I already have it on. The changes in the status bar are the only way I can tell the difference in the window names. Frequently they change so fast I can't get the text. This is also a cause of failures for the program won't always show the information in the status bar. That is why I was going with a mix of sleep statements to make it more stable.

If there is not any unique status bar text, then try sending a control-F to the IE window of interest to do a "Find (on This Page)". Search for the text that identifies the field of interest. Once that text is "found", tab from there... but not all web pages let the tab order be influenced by such a search/highlight/tab.

I tried that. I can do a search and find the word "Group" right above the field I want, but AutoIt can't see it. o:) ?

In the original post, I showed the Active Window info for that window. The only time I can see something change is if I move the mouse over the control. Again, I stress I can not use a mouse control to solve this problem.

Also, I noticed that you wait for "Opening" and then "Done" in the status bar. Does the status bar change back and forth between "Opening" and "Done" while loading? If so, I may have some code that can help with that - if I can find it.

Yes to your question. It was the only way I could tell the state of the window. Again, Autoit can't see the text inside the window, even if I have hidden text turned on. The only hidden text it sees is "??"

:lmao:

I take it there isn't a way to see the text cursor?

Link to comment
Share on other sites

...I tried that. I can do a search and find the word "Group" right above the field I want, but AutoIt can't see it...

I did not make myself clear. Forget about AutoIt for a minute. Manually go to the page of interest. Manually tab to a field that you do not want to be in. Manually send a control-f. Manually type in the word Group. Manually hit enter. Manually escape out of the "Find" dialog box. Hopefully, the word "Group" should be highlighted within the web page. Now manually tab one time and see if you are in the field of interest. If that works for you as a human then script it.

As for manually tabbing thru all of the fields and looking for a reference: I take it you dont have any links on the page like the one that I mentioned in the Yahoo illustration... The Active Window info that you posted does not let me see what AutoIt can see for every tab position on the page including any links that might not be fields (like in the Yahoo illustration). These links can be used as a reference if the status bar info is unique. [Again, I might not be making myself clear on this point. Do you understand what I did on the Yahoo page? Can you do that on your page?]

I understand that AutoIt does not see the text inside a web page believe me, I understand that... that is why I asked if you get "Opening", "Done", "Opening", "Done", "Opening" .... and finally: "Done"? If you just get one "Opening" and then one "Done", then you dont need the loop that I made once to deal with that.

You said, I take it there isn't a way to see the text cursor. Well, the pixel function might be able to see it... but lets not go there just yet.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

how about focusing the URL-bar and then tabbing yourself into the webpage ?

How do you know when the page has finished loading to start your tabbing?

Edit: "Tabbing around" for something that makes a unique status bar appear might mean that the page has loaded - or at least the part of the page that you want to work with. It is possible to send all of the desired text to a page that has not completely loaded, send enter and wait for the next page without the first page ever completely loading. I learned that while suffering with a dialup connection.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

@plato

The only way I can tell when I can tab is when line 10 is done.

WInWaitActive( "Unicenter ServicePlus Service Desk" , "Done", 1 )

@plato:

I did not make myself clear. Forget about AutoIt for a minute. Manually go to the page of interest. Manually tab to a field that you do not want to be in. Manually send a control-f. Manually type in the word Group. Manually hit enter. Manually escape out of the "Find" dialog box. Hopefully, the word "Group" should be highlighted within the web page. Now manually tab one time and see if you are in the field of interest. If that works for you as a human then script it.

Thats what I'm doing now. The problem is determining when the window is available to tab in.

Second, doing a find, then tabing to where I need doesn't work for it won't change the focus to that control after I do a find and the control is highlighted. Again, it goes back to the custom java they use. :lmao: I can only do a tab from the beginning, and I have to wait for the window to be active. That is why I wanted to see if I could detect where the text cursor was, then I could know for sure how many times I needed to tab. Also, if I tab too early, it will go back to the addres bar, causing a failure. Like I said, custom Java.

It would be a good feature to have a way to capture stuff in a webpage while it loads, like capturing all the information displayed in the status bar while a page loads

I tried to use the record tool, and this is what is got:

WinWait("Unicenter ServicePlus Service Desk - Incident List","")
If Not WinActive("Unicenter ServicePlus Service Desk - Incident List","") Then WinActivate("Unicenter ServicePlus Service Desk - Incident List","")
WinWaitActive("Unicenter ServicePlus Service Desk - Incident List -","")
Send("{ALTDOWN}e{ALTUP}{ALTDOWN}i{ALTUP}")
WinWait("Unicenter ServicePlus Service Desk - Incident Search","")
If Not WinActive("Unicenter ServicePlus Service Desk - Incident Search","") Then WinActivate("Unicenter ServicePlus Service Desk","")
WinWaitActive("Unicenter ServicePlus Service Desk - Incident Search","")
Send("{TAB}{TAB}{SHIFTDOWN}c{SHIFTUP}{SHIFTDOWN}t{SHIFTUP}{SHIFTDOWN}s{SHIFTUP}-{SHIFTDOWN}m{SHIFTUP}{SHIFTDOWN}a{SHIFTUP}{ALTDOWN}s{ALTUP}")

I ran it in a test, and it failed. It gets stuck on waiting for a window. tried again, and it got stuck again.

The "opening done, opening done" thing, that is the sequence that is shown in the status bar before I can tab and get to the field I need.

Back to my original question. Is there any way to find where the text cursor is?

Link to comment
Share on other sites

Thanks for your patience with me today. I apologize if Ive wasted you time on this. Ill leave you with this pseudo code for what it is worth:

$count = 0

Do

Sleep(10)

If WinExists (title, Opening) Then $count = 0

If WinExists (title, Done) Then $count = $count + 1

Until $count = 30

WinGetCaretPos or the pixel functions might be able to give you the x, y coords for the text cursor, but I did not think that there was a known relationship between that and any field.

later

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

WinGetCaretPos or the pixel functions might be able to give you the x, y coords for the text cursor, but I did not think that there was a known relationship between that and any field.

later

The way I have used the WinGetCaretPos is with the use of a INI file. I have a program running in a loop with tooltip that will give me the results of the WinGetCaretPos (setup Program) then I continue to each field on the screen. I then take these and place them in the INI file so that the "main" program will look at the list of values and know where it is. It will then correct itself if it checks and finds it is in the wrong spot, then continues. Does that make sense lol. Edited by strate
INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...