sending control code in ObjectSendText command question

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Randall
Junior Coder
Posts: 38
Joined: Fri Jan 13, 2012 4:39 am

sending control code in ObjectSendText command question

Post by Randall » Sun Feb 12, 2012 7:22 am

Exactly how do I send backspaces (multiple number of them) inside the ObjectSendText> command?

The command seems to want to take everything at string value, but I need to send backspaces to an edit class. (a box inside a window)

I did get the edit handle just fine, and sending normal text to it works great, but I have to remove the previous text that is displayed in this box and write new text instead.

Any ideas? I tried "\015" {'\015\} Ascii>15, and other approaches but they all have failed. I can do this by the keyboard manually of course, but I am trying to automate this.

The function wants 2 parameters.

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Sun Feb 12, 2012 3:13 pm

I had the same problem a while back with sending a new URL to Chrome's address bar. Below is my solution. I used ObjectSendKeys and Virtual key codes to delete the current URL one character at a time. There is probably a better solution but this gets the job done for me.

Code: Select all

GetWindowHandle> - Google Chrome*,hWndParent
//find Google Chrome's address bar
FindObject>hWndParent,Chrome_OmniboxView,,1,hWnd,X1,Y1,X2,Y2,result
//Get length of URL
Length>%result%,URLlen
//Delete each character of the URL by using
//Virtual Key 46 (VK46=Delete Key)
Repeat>URLlen
//Keep sending the delete key until the URL is deleted
ObjectSendKeys>hWnd,VK46
sub>URLlen,1
Until>URLlen<0
//Enter a new URl and send Enter key
ObjectSendKeys>hWnd,{"http://www.mjtnet.com/vkcodes.htm"},VK13


Randall
Junior Coder
Posts: 38
Joined: Fri Jan 13, 2012 4:39 am

some additional information on emptying an edit box

Post by Randall » Mon Feb 13, 2012 12:23 am

Getting control codes sent to a windows object was NOT as simple as it first seemed.

1. The ObjectSendKey wizard did work, but created squares instead of the correct VK codes. Then when the macro was to be executed, the synatax checker saw the funny square boxes and said "Eliminate them?"

Of course they didn't work.

While experimenting around with the Wizard, suddenly things started working ONLY when I inputted from the numeric keypad, not the main keyboard.

Backspaces did backup all right but did NOT replace the text, despite the fact that manually doing this from the keyboard works as we would expect.

I found that backspace took me to the left hand side of the edit box but then the sendtext command or ObjectSendText command put the new text in place, as desired, but pushed the old text farther to the right.

This definitely would NOT work.

By more trial and error (dozens of minutes) I found that using the Home key from the numeric keypad and then hitting the Delete Key several times from the Keyboard while using the ObjectSendKey Wizard resulted in code that actually did what I wanted, which is to erase the old text and empty the edit box for new data.

Then finally I could enter in the new data in a clean edit box.

This took about 90 mins of troubleshooting to find a good solution, so I am passing this along as a potential tip.

Running Windows XP sp 3 full professional edition, so I don't know what's up with the reason why the wizard won't work from the straight keyboard, but forces one to use the keypad instead for the VK codes to show up in the wizard?

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Mon Feb 13, 2012 4:41 pm

In a past application I remember using Ctrl + A to select evrything and then 1 Backspace to erase everything.

Could you use Ctrl + A and then enter your new data which would replace the old?
Thanks,
Jerry

[email protected]

Randall
Junior Coder
Posts: 38
Joined: Fri Jan 13, 2012 4:39 am

agree with shortest keystrokes as possible

Post by Randall » Mon Feb 13, 2012 7:18 pm

If Control-A selects all the text, this is a better solution, because it applies in all cases. Thanks for that comment.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts