Sendkey Command Has Trouble Working in a Dialog Box

Sendkey Command Has Trouble Working in a Dialog Box

Anonymous
Not applicable
3,238 Views
22 Replies
Message 1 of 23

Sendkey Command Has Trouble Working in a Dialog Box

Anonymous
Not applicable
I am trying to trigger a series of about 10 sendkeys statements which I am trying to run from VBA.

What I notice with said sendkeys series of statements is it seems to be able to execute the first sendkeys call as I intended it, i.e. pop out a dialog box but then the -- 2nd to the 10th sendkeys call all end up on the command line instead of going to the dialog box (popped out by my first sendkeys statement) of which I intended all the those sendkeys statements to go.

The command buttons are not triggerable from the command line of AutoCAD -- so I really have no choice but to try to manipulate those command buttons using sendkeys.

Please help me with any idea you have in mind.

Gratefully,
Matt
0 Likes
3,239 Views
22 Replies
Replies (22)
Message 2 of 23

Mikko
Advocate
Advocate
Sounds like after you have the new dialog box pop up you haven't set focus to it to receive the commands.
0 Likes
Message 3 of 23

Anonymous
Not applicable
You have to send the key strokes from outside. It could be VB, VBScript, Excel VBA but not from within AutoCAD VBA. -- Best Regards, Jimmy Bergmark CAD and Database Developer Manager at www.pharmadule-emtunga.com Blog: http://jtbworld.blogspot.com JTB FlexReport (FLEXnet / FLEXlm report tool) - www.jtbworld.com/jtbflexreport SmartPurger (Purges automatically) - www.jtbworld.com/?/smartpurger.htm or download some freeware at www.jtbworld.com More on AutoCAD 2005; www.jtbworld.com/autocad2005.htm "matt_1ca" wrote in message news:6440916.1109266700176.JavaMail.jive@jiveforum2.autodesk.com... >I am trying to trigger a series of about 10 sendkeys statements which I am >trying to run from VBA. > > What I notice with said sendkeys series of statements is it seems to be > able to execute the first sendkeys call as I intended it, i.e. pop out a > dialog box but then the -- 2nd to the 10th sendkeys call all end up on > the command line instead of going to the dialog box (popped out by my > first sendkeys statement) of which I intended all the those sendkeys > statements to go. > > The command buttons are not triggerable from the command line of > AutoCAD -- so I really have no choice but to try to manipulate those > command buttons using sendkeys. > > Please help me with any idea you have in mind. > > Gratefully, > Matt
0 Likes
Message 4 of 23

Anonymous
Not applicable
Hello Mikko,

Thanks for you reply, but dialog box that pops out automatically has the focus .. good example is sendkeys "%(FO)" -- file dialog box opens up but succeeding sendkeys calls dont go to that dialog box instead my observation is that it is going to the command line.

Matt
0 Likes
Message 5 of 23

Anonymous
Not applicable
Hello Jimmy,

Thanks for your reply, I am trying your suggestion right now -- i.e. calling sendkeys from VB standalone, I notice right away that its a bit more manageable but still the problem persists -- I will look at it more intently and run more tests.

Matt
0 Likes
Message 6 of 23

Anonymous
Not applicable
Hi Matt, You may find it easier to avoid opening the dialog box. Set Filedia = 0 and CmdDia = 0 and send the keys. Try it from the command line first to see exactly what you need. -- Laurie Comerford CADApps www.cadapps.com.au "matt_1ca" wrote in message news:6440916.1109266700176.JavaMail.jive@jiveforum2.autodesk.com... > I am trying to trigger a series of about 10 sendkeys statements which I am trying to run from VBA. > > What I notice with said sendkeys series of statements is it seems to be able to execute the first sendkeys call as I intended it, i.e. pop out a dialog box but then the -- 2nd to the 10th sendkeys call all end up on the command line instead of going to the dialog box (popped out by my first sendkeys statement) of which I intended all the those sendkeys statements to go. > > The command buttons are not triggerable from the command line of AutoCAD -- so I really have no choice but to try to manipulate those command buttons using sendkeys. > > Please help me with any idea you have in mind. > > Gratefully, > Matt
0 Likes
Message 7 of 23

Anonymous
Not applicable
The next thing I did was to get the Hwnd for AutoCAD and use SetForegroundWindow on it. What it does is just go and pull down the necessary file menu from the top menu. Which means that when I do a :

SendKeys "%(FO)"
SendKeys "{TAB 11}"
SendKeys "{DOWN 1}"
SendKeys "{ENTER}"

I am expecting that it will open for me my file mama.dwg -- but the only thing it does is do the equivalent of SendKeys "%F" i.e. it is just pulling down the drop down menu.

Thanks for all the kind help you can extend on this matter.

Matt
0 Likes
Message 8 of 23

Anonymous
Not applicable
Matt, What are the SendKeys statements attempting to do? You may be able to accomplish what you need without using SendKeys or SendCommand. This would make your code much more stable. James "matt_1ca" wrote in message news:6440916.1109266700176.JavaMail.jive@jiveforum2.autodesk.com... > I am trying to trigger a series of about 10 sendkeys statements which I am trying to run from VBA. > > What I notice with said sendkeys series of statements is it seems to be able to execute the first sendkeys call as I intended it, i.e. pop out a dialog box but then the -- 2nd to the 10th sendkeys call all end up on the command line instead of going to the dialog box (popped out by my first sendkeys statement) of which I intended all the those sendkeys statements to go. > > The command buttons are not triggerable from the command line of AutoCAD -- so I really have no choice but to try to manipulate those command buttons using sendkeys. > > Please help me with any idea you have in mind. > > Gratefully, > Matt
0 Likes
Message 9 of 23

Anonymous
Not applicable
What are you doing exactly as there may be a better way of doing it.
Regards - Nathan
0 Likes
Message 10 of 23

Anonymous
Not applicable
Hello Nathan,

Thank you for your reply -- here is the additional information:

There is a third party application making AutoCAD work with a separate Spatial Database. But its API does not expose all the functions that I need which prevents me from working full blast without using interactive sendkeys.

My task is this: users can work with it manually but it is taking to much time so I need to automate their repetitive task of interactively clicking on each of those dialog boxes that the 3rd party application uses.

Third party application creates a drop down menu addition to the standard AutoCAD menu. And that drop down menu is where I am supposed to start the automation process.

Matt
0 Likes
Message 11 of 23

Anonymous
Not applicable
VB.NET has a SendKeys.Send method that just sends the keys and a SendKeys.SendWait that sends the keys and waits for them to be processed.
Regards - Nathan
0 Likes
Message 12 of 23

Anonymous
Not applicable
Hello Nathan,

Thank you for your reply.

I am not sure but I think that is the same or close to the VB6 sendkeys boolean option which is the second argument in the SendKeys, I have not really used that second argument.

Sendkeys stringToSend, boolean

I think it deals with the timing when the string is sent via sendkeys. I do not know if it has the ability to control which thread receives the strings sent by sendkeys.

Matt
0 Likes
Message 13 of 23

Anonymous
Not applicable
Hello Laurie,

Thank you for your reply.

Your idea has given me a good start, out of the seven clicks on the dialog boxes your technique allowed me to find a way to call two of those clicks from the command line -- I still need to click five buttons though, and I am not finding it possible from command line.

Setting cmddia/filedia to zero has not gotten rid of the dialog box -- I think they are like dialog boxes used by vbaman which are not disabled despite cmddia/filedia settings of zero.

Even though cmddia/filedia did not disable the dialog boxes that pop out your idea made me look into the command line to see what commands are being pumped in the command line that I was able to use to my advantage.

Those other five buttons dont show any corresponding commands in the command line, so I cannot call them the way I called the other two. One of those five buttons for example activates a browser window to select files to use as templates for spatial data extraction and repopulating AutoCAD based on user's new SQL etc.

Matt
0 Likes
Message 14 of 23

Anonymous
Not applicable
Hi Matt, Once you establish that you cannot avoid a dialog box from another program with SendKey/SendCommand type processes, then the next step it to bypass the dialog box and write your own code to perform the functions behind the dialog box. If the whole function behind the dialog box is too complex for you to code, then ultimately you may be better off opening the box and allowing the user to process it manually. If you are totally insistent of using the dialog box, the next level of complexity may be to drive mouse clicks at the relevant screen coordinates of the items on the form. -- Laurie Comerford CADApps www.cadapps.com.au "matt_1ca" wrote in message news:19101957.1109290375034.JavaMail.jive@jiveforum1.autodesk.com... > Hello Laurie, > > Thank you for your reply. > > Your idea has given me a good start, out of the seven clicks on the dialog boxes your technique allowed me to find a way to call two of those clicks from the command line -- I still need to click five buttons though, and I am not finding it possible from command line. > > Setting cmddia/filedia to zero has not gotten rid of the dialog box -- I think they are like dialog boxes used by vbaman which are not disabled despite cmddia/filedia settings of zero. > > Even though cmddia/filedia did not disable the dialog boxes that pop out your idea made me look into the command line to see what commands are being pumped in the command line that I was able to use to my advantage. > > Those other five buttons dont show any corresponding commands in the command line, so I cannot call them the way I called the other two. One of those five buttons for example activates a browser window to select files to use as templates for spatial data extraction and repopulating AutoCAD based on user's new SQL etc. > > Matt
0 Likes
Message 15 of 23

Anonymous
Not applicable
Hello Laurie,

Thank you for your reply.

Actually I am not really that sure if there is just a magical trick about sendkeys that I am missing out on.

For example I know that for usual applications sendkeys is called after a call to AppActivate -- but I am not sure how or if its supposed to be implemented in AutoCAD. I am only guessing that it is not needed in AutoCAD because it is already the active application.

There is also another issue about how to implement a modeless form (again I am not sure how critical that is .. what I did was just to do a me.hide ) -- there is a gray area there because I am not understanding the why/how behind it and I am not quite sure if it is the one stopping me from properly using sendkeys with AutoCAD.

In your experience what are the common pitfalls of people who are trying to use sendkeys in AutoCAD?

Matt
0 Likes
Message 16 of 23

Anonymous
Not applicable
Matt, This will be very hard to code and very unpredicted in behaviour if you rely on several SendKey sequences. Maybe most important thing is that key sequences sent out of VB/VBA are not in synch with what ACAD is really processing at the moment. The only viable solution is, as Nathan said, using VB.NET's SendKeys.SendWait method. There's also a solution to GetObject ACAD externally, send a key sequence and check for command line results (in the meantime DoEvents must be in progress), responding to them accordingly. Did you try LISP's (Command "..." "..." "...")? Regards, Maksim Sestic "matt_1ca" wrote in message news:31022006.1109284525110.JavaMail.jive@jiveforum1.autodesk.com... > Hello Nathan, > > Thank you for your reply -- here is the additional information: > > There is a third party application making AutoCAD work with a separate Spatial Database. But its API does not expose all the functions that I need which prevents me from working full blast without using interactive sendkeys. > > My task is this: users can work with it manually but it is taking to much time so I need to automate their repetitive task of interactively clicking on each of those dialog boxes that the 3rd party application uses. > > Third party application creates a drop down menu addition to the standard AutoCAD menu. And that drop down menu is where I am supposed to start the automation process. > > Matt
0 Likes
Message 17 of 23

Anonymous
Not applicable
Matt, One problem with SendKeys is that the user can do things between when the program starts running and when the keys get sent that can disrupt the sequence. For example, I have a VBA app that has to open and close the page setup dialog box to get plot settings to stick (at least that was the only way I could find). So I do a SendKeys {ENTER} to close the dialog box right before I do a SendCommand "PAGESETUP". 9 times out of 10 it works fine... but if the user hits ENTER after they run the macro, but before it gets to my PageSetup call, for some reason it causes the dialog box to sit there open waiting for them to close it. No problem with my simple program, but it would be a disaster for a complicated database routine. Hmmm...maybe if I could clear the keyboard buffer right before my SendKeys this would not happen... I will investigate.... thanks for the idea. Just my 0.02... James "matt_1ca" wrote in message news:12075357.1109345683417.JavaMail.jive@jiveforum1.autodesk.com... > Hello Laurie, > > Thank you for your reply. > > Actually I am not really that sure if there is just a magical trick about sendkeys that I am missing out on. > > For example I know that for usual applications sendkeys is called after a call to AppActivate -- but I am not sure how or if its supposed to be implemented in AutoCAD. I am only guessing that it is not needed in AutoCAD because it is already the active application. > > There is also another issue about how to implement a modeless form (again I am not sure how critical that is .. what I did was just to do a me.hide ) -- there is a gray area there because I am not understanding the why/how behind it and I am not quite sure if it is the one stopping me from properly using sendkeys with AutoCAD. > > In your experience what are the common pitfalls of people who are trying to use sendkeys in AutoCAD? > > Matt
0 Likes
Message 18 of 23

Anonymous
Not applicable
Hello James,

Thanks for your reply --

What my sendkeys try to do is to click a cascaded menu item from a top menu (third party sitting along with all the other AutoCAD standard top menu). Then to change the content of a drop down list and click a command button from the dialog box that that cascaded menu item click activates

There are two or three more clicks I need to send from the next dialog box activated from the first dialog box command button click but initially the above describes what I need to do.

I need to do everything I described without any user intervention and right now I moved all the code to VB.

I am right now looking into your suggestion -- I am trying to see if there is another way to do it -- I am also looking at Laurie's suggestion on driving the mouse using code thanks.

Gratefully,
Matt
0 Likes
Message 19 of 23

Anonymous
Not applicable
Hello Maksim,

Thanks for your reply. I really appreciate it.

Two commands out of those seven I can check as you are suggesting. (The first time I tried using those was when Laurie suggested that I try to manipulate cmddia and filedia.)

Unfortunately the other five do not send anything at all to the command line -- they look like they trigger internal data passes and manipulation using data between two dialog boxes successively triggered by clicks on command buttons owned by those two dialog boxes i.e. they leave no trace at all on the command line. So solving those five remaining clicks using (Command ".." "..") is not likely.

Gratefully,
Matt
0 Likes
Message 20 of 23

Anonymous
Not applicable
Hi Matt, The command in the menu can be run by finding the function the menu calls and calling it directly. That will reduce the complexity of your sendcommand, so that you are not calling the menu. I think you should give some more detail of what you are trying to do. That way you will be able to get better help. Start with the principle that you should not be using SendCommand unless you absolutely have too and see where you go from that. -- Laurie Comerford CADApps www.cadapps.com.au "matt_1ca" wrote in message news:27505176.1109517324189.JavaMail.jive@jiveforum2.autodesk.com... > Hello James, > > Thanks for your reply -- > > What my sendkeys try to do is to click a cascaded menu item from a top menu (third party sitting along with all the other AutoCAD standard top menu). Then to change the content of a drop down list and click a command button from the dialog box that that cascaded menu item click activates > > There are two or three more clicks I need to send from the next dialog box activated from the first dialog box command button click but initially the above describes what I need to do. > > I need to do everything I described without any user intervention and right now I moved all the code to VB. > > I am right now looking into your suggestion -- I am trying to see if there is another way to do it -- I am also looking at Laurie's suggestion on driving the mouse using code thanks. > > Gratefully, > Matt
0 Likes