G
Guest
I Have a question. I use C# to send messages for other wondows.
In my example it is windows notepad.exe
So after I found handle of this window I can send WM_CHAR event.
But I need help with other two types of events.
How can I send
1) Some system key like "F5" ?
2) some combination of them? For example Alt + V ?
This is code which use now.
[DllImport("User32.dll")]
public static extern Int32 FindWindow(String lpClassName, String
lpWindowName);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SendMessage(int hWnd, int msg, int wParam,
int lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr
childAfter, string className, string windowTitle);
private const int WM_KEYDOWN = 256;
int hwnd = FindWindow(null, "1.txt - Notepad");
if (hwnd != 0)
{
IntPtr hwndChild = IntPtr.Zero;
hwndChild = FindWindowEx((IntPtr)hwnd, IntPtr.Zero, "Edit", null);
int Key = (int)'D';
//send BN_CLICKED message
SendMessage((int)hwndChild, WM_CHAR, (int)Key, 0);
IntPtr first = new IntPtr(1);
IntPtr second = new IntPtr((int)3F);
//send F5
Keys key = Keys.F5;
SendMessage((int)hwndChild, WM_KEYDOWN, (int)key, 1 | (int)3F);
}
In my example it is windows notepad.exe
So after I found handle of this window I can send WM_CHAR event.
But I need help with other two types of events.
How can I send
1) Some system key like "F5" ?
2) some combination of them? For example Alt + V ?
This is code which use now.
[DllImport("User32.dll")]
public static extern Int32 FindWindow(String lpClassName, String
lpWindowName);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SendMessage(int hWnd, int msg, int wParam,
int lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr
childAfter, string className, string windowTitle);
private const int WM_KEYDOWN = 256;
int hwnd = FindWindow(null, "1.txt - Notepad");
if (hwnd != 0)
{
IntPtr hwndChild = IntPtr.Zero;
hwndChild = FindWindowEx((IntPtr)hwnd, IntPtr.Zero, "Edit", null);
int Key = (int)'D';
//send BN_CLICKED message
SendMessage((int)hwndChild, WM_CHAR, (int)Key, 0);
IntPtr first = new IntPtr(1);
IntPtr second = new IntPtr((int)3F);
//send F5
Keys key = Keys.F5;
SendMessage((int)hwndChild, WM_KEYDOWN, (int)key, 1 | (int)3F);
}