Sendkey Command Has Trouble Working in a Dialog Box

Discussion in 'AutoCAD' started by matt_1ca, Feb 24, 2005.

  1. matt_1ca

    matt_1ca Guest

    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
     
    matt_1ca, Feb 24, 2005
    #1
  2. 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
     
    Jimmy Bergmark, Feb 24, 2005
    #2
  3. matt_1ca

    matt_1ca Guest

    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
     
    matt_1ca, Feb 24, 2005
    #3
  4. 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

    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.
    AutoCAD -- so I really have no choice but to try to manipulate those command
    buttons using sendkeys.
     
    Laurie Comerford, Feb 24, 2005
    #4
  5. matt_1ca

    matt_1ca Guest

    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
     
    matt_1ca, Feb 24, 2005
    #5
  6. 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


    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.
    AutoCAD -- so I really have no choice but to try to manipulate those command
    buttons using sendkeys.
     
    James Belshan, Feb 24, 2005
    #6
  7. What are you doing exactly as there may be a better way of doing it.
    Regards - Nathan
     
    Nathan Taylor, Feb 24, 2005
    #7
  8. matt_1ca

    matt_1ca Guest

    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
     
    matt_1ca, Feb 24, 2005
    #8
  9. 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
     
    Nathan Taylor, Feb 24, 2005
    #9
  10. matt_1ca

    matt_1ca Guest

    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
     
    matt_1ca, Feb 24, 2005
    #10
  11. matt_1ca

    matt_1ca Guest

    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
     
    matt_1ca, Feb 25, 2005
    #11
  12. 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

    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.
    think they are like dialog boxes used by vbaman which are not disabled
    despite cmddia/filedia settings of zero.
    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.
    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.
     
    Laurie Comerford, Feb 25, 2005
    #12
  13. matt_1ca

    matt_1ca Guest

    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
     
    matt_1ca, Feb 25, 2005
    #13
  14. 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

    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.
    time so I need to automate their repetitive task of interactively
    clicking on each of those dialog boxes that the 3rd party application uses.
    AutoCAD menu. And that drop down menu is where I am supposed to start the
    automation process.
     
    Maksim Sestic, Feb 25, 2005
    #14
  15. 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

    sendkeys that I am missing out on.
    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.
    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.
     
    James Belshan, Feb 25, 2005
    #15
  16. matt_1ca

    matt_1ca Guest

    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
     
    matt_1ca, Feb 27, 2005
    #16
  17. matt_1ca

    matt_1ca Guest

    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
     
    matt_1ca, Feb 27, 2005
    #17
  18. 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

    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
    box activated from the first dialog box command button click but initially
    the above describes what I need to do.
    right now I moved all the code to VB.
    is another way to do it -- I am also looking at Laurie's suggestion on
    driving the mouse using code thanks.
     
    Laurie Comerford, Feb 27, 2005
    #18
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.