By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,640 Members | 2,194 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,640 IT Pros & Developers. It's quick & easy.

Problems with SendKeys and System.Windows.Forms

P: n/a
Hi,

I am relatively inexperienced with VB.Net, but I am familiar with many
concepts from programming; I have some basic level of competence with C/C++
and Perl, but I just started using VB this morning.

I am trying to write an .exe file that is essentially a script. It will
open an application, send it some commands via the keyboard, then wait for
the results and close the application.

I know exactly how to do this in Perl, unfortunately, the Perl module for
sending the {ALT} key is broken and broadcasts the keystroke to all windows.

Now that you have the background, here is the code I have:

Imports Microsoft.VisualBasic
Imports System.Windows.Forms

Module Module1

Sub Main()
Dim ProcID As Integer
' Start the Calculator application, and store the process id.
ProcID = Shell("CALC.EXE", AppWinStyle.NormalFocus)
' Activate the Calculator application.
AppActivate(ProcID)
SendKeys.SendWait("22")
SendKeys.SendWait("*")
SendKeys.SendWait("44")
SendKeys.SendWait("=")
End Sub
End Module

You'll notice I essentially copy and pasted the example from MSDN's
documentation. Here's the problem I have; when I go to build I get the
following error messages:

1.
C:\Documents and Settings\Administrator\My Documents\Visual Studio
Projects\WinScripting\Module1.vb(2): Namespace or type 'Forms' for the
Imports 'System.Windows.Forms' cannot be found.

2.
C:\Documents and Settings\Administrator\My Documents\Visual Studio
Projects\WinScripting\Module1.vb(12): Name 'SendKeys' is not declared.

I actually get Error #2 for lines 12-16, but that is hardly a surprise.

From what I understand, the problem is that in my header, I am not
successfully using the System.Windows.Forms namespace, hence the SendKeys
keyword is meaningless garbage to the compiler. The IDE does not seem to
acknowledge that such a library exists, which is terribly frustrating.

I have the following programs installed:
MS Visual Studio .Net Enterprise Architect 2003
MSDN Library October 2004
MS Visual J# .Net Redistributable Package 1.1
Microsoft Data Access Componenets

Anyway, if someone could give me a clue how to get everything to work (which
libraries I need, how to import them etc.) I would really appreciate it.

Thanks in advance,

David Kanter
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

Add a reference to system.windows.forms.dll in your app.

Ken
-------------
"David Kanter" <Da*********@discussions.microsoft.com> wrote in message
news:92**********************************@microsof t.com...
Hi,

I am relatively inexperienced with VB.Net, but I am familiar with many
concepts from programming; I have some basic level of competence with C/C++
and Perl, but I just started using VB this morning.

I am trying to write an .exe file that is essentially a script. It will
open an application, send it some commands via the keyboard, then wait for
the results and close the application.

I know exactly how to do this in Perl, unfortunately, the Perl module for
sending the {ALT} key is broken and broadcasts the keystroke to all windows.

Now that you have the background, here is the code I have:

Imports Microsoft.VisualBasic
Imports System.Windows.Forms

Module Module1

Sub Main()
Dim ProcID As Integer
' Start the Calculator application, and store the process id.
ProcID = Shell("CALC.EXE", AppWinStyle.NormalFocus)
' Activate the Calculator application.
AppActivate(ProcID)
SendKeys.SendWait("22")
SendKeys.SendWait("*")
SendKeys.SendWait("44")
SendKeys.SendWait("=")
End Sub
End Module

You'll notice I essentially copy and pasted the example from MSDN's
documentation. Here's the problem I have; when I go to build I get the
following error messages:

1.
C:\Documents and Settings\Administrator\My Documents\Visual Studio
Projects\WinScripting\Module1.vb(2): Namespace or type 'Forms' for the
Imports 'System.Windows.Forms' cannot be found.

2.
C:\Documents and Settings\Administrator\My Documents\Visual Studio
Projects\WinScripting\Module1.vb(12): Name 'SendKeys' is not declared.

I actually get Error #2 for lines 12-16, but that is hardly a surprise.

From what I understand, the problem is that in my header, I am not
successfully using the System.Windows.Forms namespace, hence the SendKeys
keyword is meaningless garbage to the compiler. The IDE does not seem to
acknowledge that such a library exists, which is terribly frustrating.

I have the following programs installed:
MS Visual Studio .Net Enterprise Architect 2003
MSDN Library October 2004
MS Visual J# .Net Redistributable Package 1.1
Microsoft Data Access Componenets

Anyway, if someone could give me a clue how to get everything to work (which
libraries I need, how to import them etc.) I would really appreciate it.

Thanks in advance,

David Kanter
Nov 21 '05 #2

P: n/a
Thanks Ken, I appreciate it.

David

"Ken Tucker [MVP]" wrote:
Hi,

Add a reference to system.windows.forms.dll in your app.

Ken
-------------
"David Kanter" <Da*********@discussions.microsoft.com> wrote in message
news:92**********************************@microsof t.com...
Hi,

I am relatively inexperienced with VB.Net, but I am familiar with many
concepts from programming; I have some basic level of competence with C/C++
and Perl, but I just started using VB this morning.

I am trying to write an .exe file that is essentially a script. It will
open an application, send it some commands via the keyboard, then wait for
the results and close the application.

I know exactly how to do this in Perl, unfortunately, the Perl module for
sending the {ALT} key is broken and broadcasts the keystroke to all windows.

Now that you have the background, here is the code I have:

Imports Microsoft.VisualBasic
Imports System.Windows.Forms

Module Module1

Sub Main()
Dim ProcID As Integer
' Start the Calculator application, and store the process id.
ProcID = Shell("CALC.EXE", AppWinStyle.NormalFocus)
' Activate the Calculator application.
AppActivate(ProcID)
SendKeys.SendWait("22")
SendKeys.SendWait("*")
SendKeys.SendWait("44")
SendKeys.SendWait("=")
End Sub
End Module

You'll notice I essentially copy and pasted the example from MSDN's
documentation. Here's the problem I have; when I go to build I get the
following error messages:

1.
C:\Documents and Settings\Administrator\My Documents\Visual Studio
Projects\WinScripting\Module1.vb(2): Namespace or type 'Forms' for the
Imports 'System.Windows.Forms' cannot be found.

2.
C:\Documents and Settings\Administrator\My Documents\Visual Studio
Projects\WinScripting\Module1.vb(12): Name 'SendKeys' is not declared.

I actually get Error #2 for lines 12-16, but that is hardly a surprise.

From what I understand, the problem is that in my header, I am not
successfully using the System.Windows.Forms namespace, hence the SendKeys
keyword is meaningless garbage to the compiler. The IDE does not seem to
acknowledge that such a library exists, which is terribly frustrating.

I have the following programs installed:
MS Visual Studio .Net Enterprise Architect 2003
MSDN Library October 2004
MS Visual J# .Net Redistributable Package 1.1
Microsoft Data Access Componenets

Anyway, if someone could give me a clue how to get everything to work (which
libraries I need, how to import them etc.) I would really appreciate it.

Thanks in advance,

David Kanter

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.