SendKeys Problem

johnpc

Member
Joined
Oct 5, 2011
Messages
8
Programming Experience
10+
When I run the following code, I get a message pertaining to the
ProcessID variable stating "ArgumentException was Unhandled",
of course the keys do not get sent to the Calculator.
(This snippet was copied directly from MS Help -Keyboard SendKeys Method.)
Any help is appreciated.

Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim ProcessID As Integer
ProcessID = Shell("Calc.exe", AppWinStyle.NormalFocus)
AppActivate(ProcessID)
My.Computer.Keyboard.SendKeys("22", True)
My.Computer.Keyboard.SendKeys("*", True)
My.Computer.Keyboard.SendKeys("2", True)
My.Computer.Keyboard.SendKeys("=", True)
End Sub
End Class
 
So if you use notepad instead, do the key presses go in there ok? (take out 22, not sure if that works, it may even want the character code rather than the actual letter)
 
VB.NET:
Shell("calc.exe", AppWinStyle.NormalFocus)
        My.Computer.Keyboard.SendKeys("2", False)

That works for me.
 
Did not work for me, I used exactly what you have shown:

Shell("calc.exe", AppWinStyle.NormalFocus)
My.Computer.Keyboard.SendKeys("2", False)

And I tried -- My.Computer.Keyboard.SendKeys("2", True) as well, but no joy!
 
Yes that works, here's the whole 9 yards
Need Form and 3 Buttons
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Public Class Form1

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

Shell("NOTEPAD.EXE", AppWinStyle.NormalFocus)

'My.Computer.Keyboard.SendKeys("John ", True)
My.Computer.Keyboard.SendKeys("22", True)

End Sub

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click

Shell("calc.exe", AppWinStyle.NormalFocus)

'Turn on the timer
Timer1.Enabled = True
'Set the interval for each timer "tick"
Timer1.Interval = 2000 'initiate 2 second delay

End Sub

Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click

Me.Close()

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

My.Computer.Keyboard.SendKeys("2", True)
My.Computer.Keyboard.SendKeys("22", True)
My.Computer.Keyboard.SendKeys("*", True)
My.Computer.Keyboard.SendKeys("2", True)
My.Computer.Keyboard.SendKeys("=", True)

Timer1.Stop()

End Sub

End Class

need Form, 3 Buttons and of course a Timer Control
 
Back
Top