Skip to content

Instantly share code, notes, and snippets.

@gouf
Created February 4, 2022 05:29
Show Gist options
  • Save gouf/a6922f9b35cc9db45f23910806fbf58d to your computer and use it in GitHub Desktop.
Save gouf/a6922f9b35cc9db45f23910806fbf58d to your computer and use it in GitHub Desktop.
namespace AutoBlueStacks;
using System.Diagnostics;
public class MouseControl {
private const int MOUSEEVENTF_LEFTDOWN = 0x2;
private const int MOUSEEVENTF_LEFTUP = 0x4;
private const int MOUSEEVENTF_MOVE = 0x0001;
public void click(int x, int y) {
NativeMethods.SetCursorPos(x, y);
NativeMethods.mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
}
using System.Runtime.InteropServices;
namespace MyProgram;
public static class NativeMethods {
// マウスカーソル移動
[DllImport ("user32.dll")]
public static extern bool SetCursorPos (int X, int Y);
// ウィンドウを検索
[DllImport("user32.dll", SetLastError=true, CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
// ウィンドウサイズを Rect に転写
[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hwnd, ref Rect rectangle);
// 指定ウィンドウのフォアグラウンド制御
[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
// マウス操作の送出
[DllImport("user32.dll")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment