Static external bool PostMessage(int hwnd, int msg, uintparam, uintparam);
Parameter description: inthwnd, intmsg, uintparam, uintparam.
The first parameter is the window handle of Notepad, which must be confirmed.
The second parameter is the message window message. Try using WM_CHAR. You need to define WM_CHAR in C# or directly fill in the value 0x0 102 of WM_CHAR.
The third parameter is filled with the key code of H.
The fourth parameter is the feature code.
Use the system;
Use the system. Assemble. Generics;
Use the system. Linq
Use the system. Text;
Use the system. Runtime . InteropServices
Use the system. Drawing;
Namespace TankLibrary
{
Public class Win32API
{
[DllImport("user32.dll ",EntryPoint = "FindWindow ",CharSet = CharSet。 Automatic)]
public static extern int ptr FindWindow(string LP class name,string lpWindowName);
[DllImport("user32.dll")]
public static extern int ptr GetDC(int ptr hwnd);
[DllImport("Gdi32.dll")]
public static extern uint get pixel(int ptr hdc,int nXPos,int ny pos);
[DllImport("user32.dll")]
public static extern int mouse _ event(int dw flags,int dx,int dy,int cButtons,int dwExtraInfo);
const int mouse eventf _ MOVE = 0x 000 1; //Move the mouse
public const int mouse eventf _ left down = 0x 0002; //Simulate pressing the left mouse button
public const int mouse eventf _ left up = 0x 0004; //Simulate the lifting of the left mouse button.
const int mouse eventf _ right down = 0x 0008; //Simulates pressing the right mouse button.
const int mouse eventf _ right up = 0x 00 10; //Simulate raising the right mouse button.
const int mouse eventf _ MIDDLEDOWN = 0x 0020; //Simulates the middle mouse button pressing.
const int mouse eventf _ middle up = 0x 0040; //simulate middle mouse button lifting
const int mouse event f _ ABSOLUTE = 0x 8000; //Indicates whether absolute coordinates are used.
public const int HWND _ TOPMOST =- 1;
Public const int SWP _ display window = 40;
[StructLayout(LayoutKind。 Continuous)]
RECT public building
{
public int left
public int top
Public int rights;
public int bottom
}
[DllImport("user32.dll ",EntryPoint = "SetWindowPos")]
public static extern int SetWindowPos(int hWnd,int hWndInsertAfter,int x,int y,int cx,int cy,int w flags);
[DllImport("user32.dll")]
public static extern IntPtr GetWindowRect(IntPtr hWnd,ref RECT rect);
[DllImport("user32.dll")]
public static extern IntPtr GetWindowRect(IntPtr hWnd,ref Rectangle rect);
[DllImport("user32.dll")]
public static extern int 32 ReleaseDC(int ptr hwnd,int ptr hdc);
[DllImport("user32 ",CharSet = CharSet。 Ansi,SetLastError = true,ExactSpelling = true)]
Public static externbool setforegroundwindow (intptrhwnd);
[DllImport("user32.dll ",EntryPoint = "PostMessage")]
public static extern int ptr postmessage 1(int ptr hWnd,uint Msg,int wParam,int lParam);
[DllImport("user32.dll")]
public static extern bool SetCursorPos(int x,int y);
Public static void ClickOn(IntPtr hwnd, int x, int y)
{
uint WM _ LBUTTONDOWN = 0x 020 1;
uint WM _ LBUTTONUP = 0x0202
PostMessage 1(hwnd,WM_LBUTTONDOWN,x,y);
PostMessage 1(hwnd,WM_LBUTTONUP,x,y);
}
}
}