Discussion:
Problem SendKeys in vb.net Solidworks Addin
(too old to reply)
animaniacs
2012-08-01 18:48:24 UTC
Permalink
Hi,

I converted a macro in VBA to a Solidworks Addin in Vb.net
And I have a problem with the Sendkeys function of the code:

Dim swApp As Object
Sub main()
Set swApp = Application.SldWorks
SendKeys ("%(fn)") ' ( I know there is other ways to do this, I only use the "open new document" here as an example )
End Sub

When I convert it to VB.net it doesn't work. Even with a time out:

Public Sub _cbtest()
AppActivate("SolidWorks Premium 2012")
' System.Threading.Thread.Sleep(500)
SendKeys.SendWait("%(fn)")
End Sub

While this one work with wordpad:

Public Sub _cbtest()
AppActivate("WordPad")
SendKeys.SendWait("%(fn)")
End Sub
Auric__
2012-08-02 02:07:36 UTC
Permalink
Post by animaniacs
I converted a macro in VBA to a Solidworks Addin in Vb.net
[snip]
[snip]
[snip]

The regs of this group mostly know pre-.Net VB. You should ask your question
in microsoft.public.dotnet.languages.vb.
--
Cthulhu *needs* no reason to be angry!
Theo Tress
2012-08-02 10:59:20 UTC
Permalink
Post by Auric__
The regs of this group mostly know pre-.Net VB. You should ask your question
in microsoft.public.dotnet.languages.vb.
But if one works and the other not I think it could be not a question of
programming language used rather than a logical one, in this case that the
argument 'program name' might be false in the first one. Could imagine that
this could have been changed from VBclassic to VB.net.
DaveO
2012-08-02 15:38:47 UTC
Permalink
Post by animaniacs
Hi,
I converted a macro in VBA to a Solidworks Addin in Vb.net
Dim swApp As Object
Sub main()
Set swApp = Application.SldWorks
SendKeys ("%(fn)") ' ( I know there is other ways to do this, I only use
the "open new document" here as an example )
End Sub
Public Sub _cbtest()
AppActivate("SolidWorks Premium 2012")
' System.Threading.Thread.Sleep(500)
SendKeys.SendWait("%(fn)")
End Sub
Public Sub _cbtest()
AppActivate("WordPad")
SendKeys.SendWait("%(fn)")
End Sub
Hi

Blah blah, wrong group, blah blah



However there is one thing you might try, I doubt it will work but it'll
only take a few seconds to eliminate:



Instead of:

AppActivate("SolidWorks Premium 2012")

Try:

AppActivate( """" & "SolidWorks Premium 2012" & """")

(or the VB.Net equivalent)



DaveO.
animaniacs
2012-08-02 16:23:39 UTC
Permalink
Thank you for the replies, Sendkeys doesn't seems to work for some reason, I used keybd_event function instead:

<DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Unicode, EntryPoint:="keybd_event", ExactSpelling:=True, SetLastError:=True)> Public Shared Function keybd_event(ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Int32, ByVal dwExtraInfo As Int32) As Boolean
End Function

Public Sub _cbtest()
Const VK_MENU = &H12
Const VK_F = &H46
Const VK_N = &H4E

keybd_event(VK_MENU, 0, 0, 0)
keybd_event(VK_MENU, 0, 2, 0)
keybd_event(VK_F, 0, 0, 0)
keybd_event(VK_F, 0, 2, 0)
keybd_event(VK_N, 0, 0, 0)
keybd_event(VK_N, 0, 2, 0)
End Sub
Coder X
2012-08-03 20:49:41 UTC
Permalink
Blah. Unreliable for so many reasons. AppActive works when it wants to.
Get the window handle, then the hMenu , determine the menu ID using
something like Spy++ and use WM_COMMAND. Much more reliable.
Post by animaniacs
Hi,
I converted a macro in VBA to a Solidworks Addin in Vb.net
Dim swApp As Object
Sub main()
Set swApp = Application.SldWorks
SendKeys ("%(fn)") ' ( I know there is other ways to do this, I only use
the "open new document" here as an example )
End Sub
Public Sub _cbtest()
AppActivate("SolidWorks Premium 2012")
' System.Threading.Thread.Sleep(500)
SendKeys.SendWait("%(fn)")
End Sub
Public Sub _cbtest()
AppActivate("WordPad")
SendKeys.SendWait("%(fn)")
End Sub
Loading...