jpaugh78
01-19-2004, 07:05 PM
I am trying to make a form to use with AutoCAD, where when you click on the Enter button on my form, it changes the focus to AutoCAD and then feeds it information. I tried searching this forum for help, but i couldn't find anything that I understood. For this example, lets say I want to put focus on AutoCAD then have it enter:
the word "Line" then "13, 5, ENTER".
Is there any easy way to do this?
Optikal
01-19-2004, 07:13 PM
you can use the SendKeys statement
jpaugh78
01-19-2004, 07:25 PM
Could you give me an example of the SendKeys Function? Also, I still don't know how to tell it where to "send" these keys to. I have never tried this before, and i can't figure out how to get AutoCAD to get focus.....
HarvestR
01-19-2004, 10:56 PM
Could you give me an example of the SendKeys Function? Also, I still don't know how to tell it where to "send" these keys to. I have never tried this before, and i can't figure out how to get AutoCAD to get focus.....
The main idea is to enumerate all existing windows with API. You can find such code here, I guess, or everywhere in VB related sites.
When you "get" the good window, you can use SendKeys to that window.
Here is a sample code (not mine, done by Jaime Muscatelli) to enum all windows :
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=35999&lngWId=1
I hope this will give you some clues
jpaugh78
01-20-2004, 01:18 AM
Okay, I took that code and put it into a module, but how do I call on that code? I made a listbox called "list1" on my form....but how do i populate it using that code? :confused:
mertlock
01-20-2004, 01:36 AM
If you want AutoCad to receive the focus you can use the following from MSDN:
Dim MyAppID, ReturnValue
AppActivate "Microsoft Word" ' Activate Microsoft
' Word.
' AppActivate can also use the return value of the Shell function.
MyAppID = Shell("C:\WORD\WINWORD.EXE", 1) ' Run Microsoft Word.
AppActivate MyAppID ' Activate Microsoft
' Word.
' You can also use the return value of the Shell function.
ReturnValue = Shell("c:\EXCEL\EXCEL.EXE",1) ' Run Microsoft Excel.
AppActivate ReturnValue ' Activate Microsoft
' Excel.
mertlock
01-20-2004, 01:46 AM
Below are some examples of Keystrokes and how you can use them. Hope this helps.
Private Sub Command1_Click()
Call SendKeystrokes("%I")
Call SendKeystrokes("%C")
Call SendKeystrokes(STRING & "{TAB}{ENTER}")
Call SendKeystrokes("%D")
Call SendKeystrokes("%C")
Call SendKeystrokes(Trim$(TEXT1)& "{TAB}")
Call SendKeystrokes(Trim$(TEXT2) & "{TAB}")
Call SendKeystrokes(Trim$(TEXT3) & "{TAB}")
Call SendKeystrokesToCafe("{TAB}{TAB}")
Call SendKeystrokesToCafe("{TAB}{TAB}{TAB}")
Call SendKeystrokesToCafe("1{TAB}")
End Sub
Private Sub SendKeystrokes(ByVal Keystrokes As String)
On Error GoTo Err_SendKeys
AppActivate "AUTOCAD"
SendKeys Keystrokes, True
On Error GoTo 0
Exit Sub
Err_SendKeys:
MsgBox "Error: " & Err.Number & vbCrLf & vbCrLf & Err.Description, vbExclamation, "Error Sending Data To Cafe"
End Sub
mertlock
01-20-2004, 01:47 AM
You can remove the cafe from the code. Sorry, it was a quick copy and paste.
jpaugh78
01-20-2004, 01:57 AM
Hey man, thanks! I tried this for Word, and it worked great! Now i'll just have to wait until i get home to be able to test it in AutoCAD.