Saturday, March 31, 2012

Sendkeys not declared?


I just downloaded ASP.Net Web Matrix and I'm really enjoying using it, even though I only know what I am doing about 10% of the time. The one problem I've encountered is that I can't get a VB "SendKeys" statement to work in an ASPX page. I have a really simple script written. Here it is:
Sub Button1_Click(sender As Object, e As EventArgs)
Shell ("notepad", 1)
SendKeys ("%", True)
End Sub
The button code is:
<form id="form1" runat="server">
<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Button"></asp:Button>
</form>
When I run the page, it returns an error that states: "SendKeys statement not declared." Originally, I had no parentheses around "%, True," but ASP.NET demanded it so I put it in. Any help would be greatly appreciated. I am SendKeys-dependent.

Hi,

In .NET SendKey is a class declared in System.Windows.Forms namespace. You can use it as follows:

SendKeys.SendWait("%")

But... It is really not a good idea to open notepad at server from ASP.NET application. Is this what you intend to do?


Thank you so very much for your response. I am continuing to get the same error message, even after adaptation of the command to Sendkeys.Sendwait:

"Compiler Error Message:
BC30451: Name 'SendKeys' is not declared."

I had previously located Sendkeys as an identified namespace within System.Windows.Forms, but I am not sure what to do with that information beyond that. Is there something I need to do to get the page to "talk" with that class or namespace?

As for your caution, I appreciate it. Have read the warnings. The application is going to run only on my PC. Does that minimize the concern?
Again, thank you for your time.


Hi,
You have to reference System.Windows.Forms.dll to use this method.
I think what you want to do is to open notepad from client script and not from server side code. You can use scripting host to do it. In vbscript it will look like this:
Dim WshSHell
set WshShell = CreateObject("WScript.Shell")
WshShell.Run("notepad")
WScript.Sleep(100)
WshShell.AppActivate("Notepad")
WScript.Sleep(100)
WshShell.SendKeys("abc")

0 comments:

Post a Comment