473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Problems with SendKeys and System.Windows.Forms

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
2 11578
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gary | last post by:
I am trying to use the "System.Windows.Forms.SendKeys" class for triggering the Ctrl+P key. Syntax: System.Windows.Forms.SendKeys.Send("^(P)"); This is not working ..what could be the...
1
by: Bryan | last post by:
I am writing a C# Windows App that updates out Excel reports' modules. The app is complete, but has a problem. The only way MS allows you to unprotect the VBA code in Excel is to do it by hand or...
1
by: GrantS | last post by:
I need to use a sendkeys key combination to automate the "accept files" that a remote user wants to send to me via Windows messenger. I am using automation to work with Windows Messenger client in...
6
by: Gary | last post by:
Hi, I am trying to use the "System.Windows.Forms.SendKeys" class for triggering the Ctrl+P key. Syntax: System.Windows.Forms.SendKeys.Send("^(P)") This is not working ..what could be the...
3
by: mark | last post by:
I have a procedure that needs to put characters into the current insertion point of a textbox. This insertion point is not necessarily the end of the current string so textbox1.text &= "?" won't...
1
by: Glenn Palomar | last post by:
Hi, I have a beta Vista system and I'm running a program (created in VB.net) that sends keystroke to an application using System.Windows.Forms.SendKeys.SendWait. In Vista it throws an exception...
9
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I have this code for sendKeys. This simply sends a text to the notepad. This method runs fine, but I don't see the notepad and the text entered in that notepad. Is there any way...
4
by: Robert Cezar | last post by:
I am trying to send: Ctrl, Shift, TAB and the number 1 contemporaneously. I am using: System.Windows.Forms.SendKeys.Send("^+{TAB}1") or
0
DOSrelic
by: DOSrelic | last post by:
I have read this page http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys(VS.71).aspx but try as I might I cannot figure out how to do it. I tried many combinations but none of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.