Emulating keyboard strokes in vb.net

P

Paulers

Hello,

I need to emulate keyboard strokes from a console application. The
console application monitors a textfile and when something is matched
in a text file I need the matched string outputted to the keyboard as
if someone was typing on the keyboard. can someone help me locate the
correct vb.net function to use?

Thanks!
 
P

Peter Proost

Have a look at:

SendKeys.Send
SendKeys.SendWait

They do what you want.

Greetz Peter
 
P

Paulers

Thanks for the response but can I use those functions from a console
application? Or does it have to be a form applicaton?
 
P

Peter Proost

I'm sorry sendkeys indeed can't be used with a console app, I read your OP
to quick.
But can't you use Console.WriteLine("The matched part")
Something like this quick sample I made, it just keeps checking c:\test.txt
until it finds some text in it and the outputs it to the console if the text
is found

Sub Main()
Console.WriteLine("Hello I'm waiting for text in c:\test.txt")
Do While checkFile() = False
Threading.Thread.CurrentThread.Sleep(1000)
Loop
End Sub

Private Function checkFile() As Boolean
Dim strMessage As String
Dim myReader As New FileStream("c:\test.txt", FileMode.Open,
FileAccess.Read)
Dim myStreamReader As New StreamReader(myReader)
strMessage = myStreamReader.ReadToEnd()
myStreamReader.Close()
myReader.Close()
If strMessage = "" Then
Return False
Else
Console.WriteLine(strMessage)
Console.ReadLine()
Return True
End If


End Function


Hope this helps,

Greetz Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top