111,131
社区成员
发帖
与我相关
我的任务
分享ClickCharKey2(MainHwnd, 32);
private void ClickCharKey2(IntPtr hwnd, char key)
{
SystemApi.SendMessage(hwnd, SystemApi.WM_KEYDOWN, key, 0);
Thread.Sleep(500);
SystemApi.SendMessage(hwnd, SystemApi.WM_KEYUP, key, 0);
}
public const int WM_KEYDOWN = 0x0100;
public const int WM_KEYUP = 0x0101;
public const int WM_CHAR = 0x0102;
public const int WM_IME_KEYDOWN = 0x0290;//适用于tab键
DllImport("user32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool SetWindowPos(IntPtr hWnd,
int hWndInsertAfter,
int X,
int Y,
int cx,
int cy,
int uFlags
);
public static void SetWindowPos(IntPtr hWnd)
{
SetWindowPos(hWnd, -1, 0, 0, 0, 0, 3);
Thread.Sleep(500);
SetWindowPos(hWnd, -2, 0, 0, 0, 0, 3);
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool IsWindowVisible(IntPtr hWnd);