Send Input Simulate Mouse Click to Focus Window - Astate - Oct 21, 2020
Hi All Insomniac ! 😴
Send Input Simulate Mouse Click to Focus !.
Pinvoke structs:
Code public const int INPUT_MOUSE = 0;
public const int INPUT_KEYBOARD = 1;
public const int INPUT_HARDWARE = 2;
[Flags]
public enum MOUSEEVENTF : uint
{
MOUSEEVENTF_ABSOLUTE = 0x8000,
MOUSEEVENTF_LEFTDOWN = 0x0002,
MOUSEEVENTF_LEFTUP = 0x0004,
MOUSEEVENTF_MIDDLEDOWN = 0x0020,
MOUSEEVENTF_MIDDLEUP = 0x0040,
MOUSEEVENTF_MOVE = 0x0001,
MOUSEEVENTF_RIGHTDOWN = 0x0008,
MOUSEEVENTF_RIGHTUP = 0x0010,
MOUSEEVENTF_XDOWN = 0x0080,
MOUSEEVENTF_XUP = 0x0100,
MOUSEEVENTF_WHEEL = 0x0800,
MOUSEEVENTF_HWHEEL = 0x01000,
}
[StructLayout(LayoutKind.Sequential)]
internal struct MOUSEINPUT
{
  internal int dx;
  internal int dy;
  internal int mouseData;
  internal MOUSEEVENTF dwFlags;
  internal uint time;
  internal UIntPtr dwExtraInfo;
}
[StructLayout(LayoutKind.Sequential)]
public struct KEYBDINPUT
{
  public ushort wVk;
  public ushort wScan;
  public uint dwFlags;
  public uint time;
  public IntPtr dwExtraInfo;
}
[StructLayout(LayoutKind.Sequential)]
public struct HARDWAREINPUT
{
  uint uMsg;
  ushort wParamL;
  ushort wParamH;
}
[StructLayout(LayoutKind.Explicit)]
public struct INPUT
{
  [FieldOffset(0)]
  public int type;
  [FieldOffset(4)] //*
  public MOUSEINPUT mi;
  [FieldOffset(4)] //*
  public KEYBDINPUT ki;
  [FieldOffset(4)] //*
  public HARDWAREINPUT hi;
}
Code
Code [DllImport("user32.dll")]
internal static extern uint SendInput(uint nInputs, [MarshalAs(UnmanagedType.LPArray), In] INPUT[] pInputs, int cbSize);
[DllImport("user32.dll")]
public static extern IntPtr SetFocus(IntPtr hWnd);
Process proc = Process.GetProcessesByName("ac_client")[0];
uint hwnd = (uint)proc.MainWindowHandle.ToInt32();
INPUT[] mInput = new INPUT[1];
mInput[0].type = INPUT_MOUSE;
mInput[0].mi.dwFlags = MOUSEEVENTF.MOUSEEVENTF_LEFTDOWN;
SetFocus(proc.MainWindowHandle);
SendInput(hwnd, mInput, System.Runtime.InteropServices.Marshal.SizeOf(mInput[0]));
RE: Send Input Simulate Mouse Click to Focus Window - saltycracker - Oct 21, 2020
I wonder if you could send a mouse click to a certain position on the GUI screen.
RE: Send Input Simulate Mouse Click to Focus Window - gurlhackerclub - Oct 27, 2020
(Oct 21, 2020 04:43 AM)saltycracker Wrote: I wonder if you could send a mouse click to a certain position on the GUI screen.
Casualgamer has good videos on mouse click events.
https://www.youtube.com/watch?v=j4VFo4acorQ
|