Author Topic: SendKeys to Dialog Box  (Read 482 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Water Moccasin
  • Posts: 2385
  • I can't remeber what I already asked! I need help!
SendKeys to Dialog Box
« on: March 27, 2019, 12:08:50 PM »
I have this vba code that I use to use with AutoCAD 2015. It was able to activate a command in autocad that would bring up a dialog box. Then it would proceed with the sendkeys on that dialog box.

I am trying the same thing in 2018 and the sendkeys do not work on the dialog box. However, when I close the dialog box, it runs the sendkeys at the command line. Not quite sure whats going on.

Thank you for any help!

Code: [Select]
Sub Catchment()

 On Error Resume Next
 Set AcadApp = GetObject(, "AutoCAD.Application")
 If Err Then
 Err.Clear
 Set AcadApp = CreateObject("AutoCAD.Application")
 End If

 AppActivate AcadApp.Caption
 AcadApp.Visible = True
 AcadApp.Application.WindowState = acNorm
 AcadApp.ActiveSpace = acModelSpace


 If AcadApp.Documents.Count = 0 Then
 AcadApp.Documents.Add
 End If

 AcadApp.ActiveDocument.SendCommand "_CREATECATCHMENTFROMOBJECT" & vbCr
 

End Sub


Sub Catchment_Storm_SendKeys()
   Dim myApp As String

DoEvents
Application.Wait (Now + TimeValue("0:00:01"))
Sleep 250
SendKeys "{TAB}{TAB}{TAB}{TAB}", True
Sleep 250
SendKeys "{ENTER}", True
Sleep 250
SendKeys "{TAB}{TAB}{TAB}{TAB}", True

End Sub
Autodesk Infrastructure Design Suite 2019

MSTG007

  • Water Moccasin
  • Posts: 2385
  • I can't remeber what I already asked! I need help!
Re: SendKeys to Dialog Box
« Reply #1 on: March 27, 2019, 01:50:16 PM »
lol. This is funny. I did not realized I asked this a few years ago.

http://www.theswamp.org/index.php?topic=49598.msg547399#msg547399
Autodesk Infrastructure Design Suite 2019

MP

  • Seagull
  • Posts: 17369
Re: SendKeys to Dialog Box
« Reply #2 on: March 27, 2019, 02:37:06 PM »
lulz. Cue the "I have alzheimer's but at  least I don't have alzheimer's" memes.

Back to your issue -- is it a case of modal vs non-modal -- i.e. it would work properly in the latter?
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

MSTG007

  • Water Moccasin
  • Posts: 2385
  • I can't remeber what I already asked! I need help!
Re: SendKeys to Dialog Box
« Reply #3 on: March 27, 2019, 02:40:51 PM »
It is modal. I have to click the OK button to dismiss it.
Autodesk Infrastructure Design Suite 2019

MSTG007

  • Water Moccasin
  • Posts: 2385
  • I can't remeber what I already asked! I need help!
Re: SendKeys to Dialog Box
« Reply #4 on: March 27, 2019, 02:47:46 PM »
Is there a way I can change a focus to the dialog box by targeting the title in the dialog box?
Autodesk Infrastructure Design Suite 2019

DavidS

  • Mosquito
  • Posts: 14
Re: SendKeys to Dialog Box
« Reply #5 on: March 28, 2019, 09:27:22 AM »
Is there a way I can change a focus to the dialog box by targeting the title in the dialog box?

https://stackoverflow.com/a/30353590
That link is referring to Excel, but in the same way Autocad/VBA will not process the remaining vba statements until the modal dialog is dismissed.

MSTG007

  • Water Moccasin
  • Posts: 2385
  • I can't remeber what I already asked! I need help!
Re: SendKeys to Dialog Box
« Reply #6 on: March 28, 2019, 09:34:54 AM »
Im trying to follow. So I can not get the handle of the modal window, but I can place a timer for the VBA to wait until out of the window? Something like that?
Autodesk Infrastructure Design Suite 2019

DavidS

  • Mosquito
  • Posts: 14
Re: SendKeys to Dialog Box
« Reply #7 on: March 28, 2019, 01:04:14 PM »
... for the VBA to wait until out of the window ...

I don't see it that way.  It appears that you won't be using the AutoCAD/VBA function SendKeys, but the Windows API SendMessage function.  The timer is a 10 millisecond delay to allow the dialog to show before the TIMERPROC is called.  The TIMERPROC function gets a handle to the dialog using FindWindow call and then issues a SendMessage to it.

Here are a couple of links that you might find useful:
https://www.google.com/search?q=windows+message+pump+vba&rlz=1C1GCEU_enUS820US820&oq=windows+message+pump+vba&aqs=chrome..69i57.8716j0j8&sourceid=chrome&ie=UTF-8
https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-settimer

Years ago I used Spy++ to see the Messages that are passed in the operating system...
https://docs.microsoft.com/en-us/visualstudio/debugger/introducing-spy-increment?view=vs-2017