Jump to content
Xtreme .Net Talk

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


Recommended Posts

Posted

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:

Posted
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.
  • 2 months later...
Posted

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)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...