Send Keys A..X <Enter>... from vb.net to notepad

Nighty

Newcomer
Joined
Mar 20, 2006
Messages
1
Hi I want to send some keys to a Notepad.

It work in VB6, but it wont work with VB.net.

I test SendMessage PostMessage, ......

Have anyone an example written in vb.net that sends keys to
a notepad that have not the focus ?
(Notepad=MyDemoAppliction, later I will send Keys to another Exe)

regards

Nighty :cool:
 
Cant say i have a clue about how to do that... But have you tried importing your VB6 app? Then look at the imported code? May give you a few pointers.
 
If you are converting a VB6 declare statement remember that under .Net all Longs are now Integer and all Integers are now Short. Also As Any is no longer supported and needs to be declared as the correct parameter types.
 
hwnd gets that handle for the notepad window. x gets tha handle for the control to send messages to (the white space). Hope this helps.


Sample Code:
------------

Private Declare Ansi Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer

Public Const WM_CHAR = &H102

' assuming you have notepad open.
Dim hwnd As Integer = FindWindow(vbNullString, "Untitled - NotePad")
Dim x As Integer = FindWindowEx(hwnd, 0, "Edit", vbNullString)

' send some keys
SendMessage(x, WM_CHAR, Keys.C, 0)
SendMessage(x, WM_CHAR, Keys.L, 0)
 
Back
Top