ObjectSendKeys ConsoleWindowClass without focus

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
wil
Junior Coder
Posts: 25
Joined: Mon Dec 06, 2010 6:00 pm

ObjectSendKeys ConsoleWindowClass without focus

Post by wil » Tue Jul 17, 2012 11:25 pm

Hello,

I want to be able to send keys and text to a dos-window without doing a focus, but i have some difficulties doing that.
For example. I open an old dos-programm 'norton commander' in a dos-box like this:
Image

When i want to send the 'dir' command to the dos-window *with* focus using the following code it works fine:

Code: Select all

SetFocus>D:\NC\NC.EXE
Send>dir
press enter
result: dir output:
Image

But when i want to send the 'dir' command *without* focus by using the following code:

Code: Select all

GetWindowHandle>D:\NC\NC.EXE,hWndParent
ObjectSendKeys>hWndParent,{"dir"},VK13
I get this:
Image
And when i run the same code again i see D:\ on the right top of the screen above. So it looks like it only accepts 'enter' (VK13)
I also tried ObjectSendText:

Code: Select all

GetWindowHandle>D:\NC\NC.EXE,hWndParent
ObjectSendText>hWndParent,{"dir"}
ObjectSendKeys>hWndParent,VK13
Same result :cry:

When i just open a dosbox (run-->cmd.exe) then
"ObjectSendKeys>hWndParent,{"dir"},VK13" works fine.

When i use the tool "view system windows" and searchfor 'NC' i get results for CabinetWClass and ConsoleWindowClas.

I hope someone can explain how to get the dir listing on the left of the window *without* using 'setfocus'

Thanks and best regards,

wil

wil
Junior Coder
Posts: 25
Joined: Mon Dec 06, 2010 6:00 pm

Post by wil » Fri Jul 20, 2012 4:06 pm

I use Macro Scheduler Pro, Version 13.1.04.

The helpfile for FindObject says "Notepad does not require focus"

This implies that there are programs that do require a focus?

tnx,

wil

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Jul 20, 2012 4:42 pm

It is not saying that some programs require focus and some don't. It is simply saying that because this is being done with ObjectSendKeys to the edit portion of Notepad, Notepad does not require focus, because ObjectSendKeys does not require the object to have focus. As opposed to the traditional SendKeys method which does.

ObjectSendKeys does not require focus, SendKeys does.

However, ObjectSendKeys will only work with windowed controls - that is controls that have a handle and classname and can be accessed via FindObject. Whereas SendKeys can send keystrokes to anything via the input buffer - the keystrokes will land on whatever has the focus at the time.

In short, ObjectSendKeys will not and can not work with everything. Suck it and see. SendKeys can, but will require the target window to be active and focused.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

wil
Junior Coder
Posts: 25
Joined: Mon Dec 06, 2010 6:00 pm

Post by wil » Fri Jul 20, 2012 5:24 pm

Hello Marcus,

Thank you for your reply.
So in my case of 'Norton Commander' it means ObjectSendKeys can not work because there is no windowed control / edit object for it?
Image
thnx,

wil

wil
Junior Coder
Posts: 25
Joined: Mon Dec 06, 2010 6:00 pm

Post by wil » Sat Jul 21, 2012 1:52 am

In short, ObjectSendKeys will not and can not work with everything.
Suck it and see. SendKeys can,
but will require the target window to be active and focused.


mmmh, not a really reliable function so.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sat Jul 21, 2012 8:37 am

It is reliable for objects it can work with. It is not that it is unreliable. It works with WINDOWED objects which will accept WM_CHAR messages. It does not work with non-windowed objects or ones that won't accept keys being sent to them.

We don't control how Windows works or how a UI is created. So you have to find an approach that works with the UI you want to automate. If one approach isn't appropriate that does not mean it is not reliable, it just isn't suitable for your scenario and you'll have to find another.

Microsoft Windows supports a plethora of technologies and there are all kinds of ways a UI can be generated. We provide ways and means of automating all of them.

But not everything can be automated without it being focused and without you simulating a user. That's not a shortcoming of Macro Scheduler, it's just a fact of life, it's down to how Windows works and down to the fact that your UI was designed to be used by a user, and was not designed for background automation.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

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