
SendKeys |
Post Reply
|
| Author | |
spectre87
Regular Member
Joined: 05 Oct 2009 Location: United States Online Status: Offline Posts: 173 |
Quote Reply
Topic: SendKeysPosted: 28 Dec 2009 at 07:18 |
|
Hi again,
I am writing a script that open excel, then uses the sendkeys to open the VBA editor. After it opens the editor I will have it continue the sendkeys, If you can help me figure out my error I can make it do the rest. My issue is... it doesn't do anything other than opening excel.
|
|
|
"The best way to predict the future is to invent it." - Alan Kay
|
|
![]() |
|
spectre87
Regular Member
Joined: 05 Oct 2009 Location: United States Online Status: Offline Posts: 173 |
Quote Reply
Posted: 28 Dec 2009 at 07:22 |
|
Nevermind I got it
|
|
|
"The best way to predict the future is to invent it." - Alan Kay
|
|
![]() |
|
jvierra
MVP
Joined: 31 Aug 2006 Location: United States Online Status: Offline Posts: 6517 |
Quote Reply
Posted: 28 Dec 2009 at 10:08 |
|
That is not the solution. The two bits are identical in the end.
You need to us4e AppActivate to teh window title just before the sendkeys to be sure nothing changes the focus.
The follwoing two lines are identical:
objShell.SendKeys "%{F11}"
objShell.SendKeys "%" & "{F11}"
The two strings will be concatenated before being sent and will be the same string as the first example.
You should take out your book and study the section on "strings".
Here is an example of SendKeys:
Notice the use of AppActivate.
Edited by jvierra - 28 Dec 2009 at 10:20 |
|
![]() |
|
spectre87
Regular Member
Joined: 05 Oct 2009 Location: United States Online Status: Offline Posts: 173 |
Quote Reply
Posted: 28 Dec 2009 at 11:55 |
|
Ok, thanks. I'm now confused on how it worked even when I was using other applications that were in focus. |
|
|
"The best way to predict the future is to invent it." - Alan Kay
|
|
![]() |
|
jvierra
MVP
Joined: 31 Aug 2006 Location: United States Online Status: Offline Posts: 6517 |
Quote Reply
Posted: 28 Dec 2009 at 13:00 |
|
Immefiately after an applicatiopn is launched there is a narrow possibility that it will be topmost for a second. It all depends on teh design of the application and what is going on in WIndows at the time of the launch. Using AppActivate will almost always but not always force the app to be the active app as long as keyboard or mouse input is available.
With Office applications it is more reliable to use automation. But then that is another topic.
|
|
![]() |
|
spectre87
Regular Member
Joined: 05 Oct 2009 Location: United States Online Status: Offline Posts: 173 |
Quote Reply
Posted: 06 Jan 2010 at 11:33 |
|
I don't know how much experience you have with Linux, but if you bring up the title bar context menu, you can select "Always On Top". Would there be a way to "force" (Using this term loosely) the application to be "On Top"???
|
|
|
"The best way to predict the future is to invent it." - Alan Kay
|
|
![]() |
|
jvierra
MVP
Joined: 31 Aug 2006 Location: United States Online Status: Offline Posts: 6517 |
Quote Reply
Posted: 06 Jan 2010 at 12:35 |
|
Linux copied that idea from Windows. Windows has always had teh concept of always on top. It has to be designed into each application from the beginning just as in Linux. The big difference is that Linux has it pinned to teh system default menu and Windows doesn't. A topmost Windows has to be a full WIndow of a certian kind that can be made a child of teh Desktop. THer ecan be more than one topmost WIndow so the idea is a bit silly although it did work back in W98.
If a Window is designed for topmost and has the attribute set then it will stay pretty much on top.
You cannot make a WIndow topmost from script in any way that I know of. I have seen third party tools which claim they can do this.
|
|
![]() |
|
spectre87
Regular Member
Joined: 05 Oct 2009 Location: United States Online Status: Offline Posts: 173 |
Quote Reply
Posted: 07 Jan 2010 at 06:12 |
|
I agree with you on everything, especially that there probably cannot make something topmost as there are no controls that you could override in windows. I checked out some third party tools, and found that the majority are written in C++ or some other form of C. If I really wanted to, I guess I could call a C++ class, but then I would have to put timers or a Select...Case. NO THANK YOU! Why would I or anyone want to call a C++ class from vbs? I don't think anyone would. It isn't important enough for me to want to spend time developing this in vbs, which isn't my native language. I guess now I see why people like to use GUI, you can set a form to be topmost.
|
|
|
"The best way to predict the future is to invent it." - Alan Kay
|
|
![]() |
|
jvierra
MVP
Joined: 31 Aug 2006 Location: United States Online Status: Offline Posts: 6517 |
Quote Reply
Posted: 07 Jan 2010 at 08:28 |
|
????
You cannot call C++ classes from any scriping language. I think you mean you need to cal a COM class or object. Most of VBS is implemented using COM classes. WMI and FileSystemObject aare COM classes.
You can't use timers in VBS so I don't know what you are trying to say.
Topmost is only something that an application can be set to do at design time. Third party tools probably hook the message loop and endravor to keep the application on top although it may be possible to hack the WIndow object in memory. None of these things canbe don usiong script. Third party tools are external to your script and usually need to be used to launch the program or need to hook the complete system.
Why would anyone want to do this anyway. If it was truly needed then the program would come with this capability I would guess.
|
|
![]() |
|
spectre87
Regular Member
Joined: 05 Oct 2009 Location: United States Online Status: Offline Posts: 173 |
Quote Reply
Posted: 07 Jan 2010 at 08:30 |
|
Oh sorry, hadn't had the coffee yet. Right, COM class or object is right. By timer I meant WScript.Sleep x. I don't know anyone who would want to do it anyways.
|
|
|
"The best way to predict the future is to invent it." - Alan Kay
|
|
![]() |
|
Post Reply
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |