Hi i'm looking for a way to make a program type the letter A thank's to the api declaration and function
Printable View
Hi i'm looking for a way to make a program type the letter A thank's to the api declaration and function
I don't know of any spelling APIs. Why API?
No problem
i've solved this problem yesterday by myself , may be that i haven't explained and developped my question .
What I wanted , is to simulate the letter A with the keyboard ; without typing it
The solution was with the function keybd_event
You might be better off using findWindow and SendMessage as its not dependant upon the receiving app having the input focus. If the user minimizes or changes the apps focus then keybd_event will fail.
ok i will try this thank you my friend
No prob. Just think of the keybd_event API as the same thing that SendKeys does.
just a question by the way , because i have a probleme with the findwindow first argument ,
let's say that i have 3 windows opened in my computer
1-MS WORD name : a
2-MS EXCEL name : b
3-NOTEPAD name : c
if i want to find the Notepad name :c
how to do that with the findwindow function
thank you
lHwnd = FindWindow("notepad", "Untitled - Notepad")
But it will only work for a blank new notepad. If notepad contains a opened file then the window caption will be different.
ok and do you know how to focus on a window
for example : if i have MS WORD and Notepad open
and in the first plan i have NOTEPAD , do you know how to do to make MS WORD on the first plan instead of Notepad
thank you .
You can use SetActiveWindow API.
my last question in sendmessage argument ; if i want to send to the
lHwnd = FindWindow("notepad", "Untitled - Notepad")
the sentence "hello world"
how can i do that with sendmessage
thank you very much for your help
Just pass the window handle and the message constant. Then the last tow arguments will be "0&" and "A"
yes but for the message constant
what is this constant if i have the message "hello world"
i mean i can't do sendmessage(hwnd,"hello world",0&,A)
WM_SETTEXT
i tried this but it doesn't work
Public Class Form1
Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Const WM_SETTEXT As Long = &HC
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Const VK_M = &H4D
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim nPad As Long
nPad = FindWindow("notepad", "essai") ' send to first notepad found.
Call SendMessageByString(nPad, WM_SETTEXT, 0, "hello world")
End Sub
End Class
Oh of course not you are using VB.NET.
The APIs and code will all need changing. Hold on ...
Here is a full working example. Note you will want to improve it with error handling and error prevention.
Code:Option Explicit On
Option Strict On
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("user32.dll", CharSet:=CharSet.Auto, EntryPoint:="SendMessage")> _
Private Shared Function SendMessage(ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As IntPtr
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto, EntryPoint:="FindWindow")> _
Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto, EntryPoint:="FindWindowEx")> _
Private Shared Function FindWindowEx(ByVal hWnd1 As IntPtr, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As IntPtr
End Function
Private Const WM_SETTEXT As Integer = &HC
Private Const VK_M As Integer = &H4D
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim nPad As IntPtr
Dim nPadChild As IntPtr
nPad = FindWindow("notepad", "Untitled - Notepad") ' send to first notepad found.
nPadChild = FindWindowEx(nPad, 0, "edit", String.Empty)
SendMessage(nPadChild, WM_SETTEXT, 0, "hello world")
End Sub
End Class
Thank you for your help
and finally if i want to put notpad in the first plan
i made
SetActiveWindow(CLng(nPad))
should i add something before because it didn't work
You need to use the .NET definition syntax for your APIs. If you dont have an API utility then download the one in my signature. API Viewer.
Code:<DllImport("user32.dll", CharSet:=CharSet.Auto, EntryPoint:="SetActiveWindow")> _
Private Shared Function SetActiveWindow (ByVal hwnd As IntPtr) As IntPtr
End Function