Add mouse events
This commit is contained in:
parent
023615069c
commit
748e5322ab
|
@ -0,0 +1,35 @@
|
|||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using CC_Functions.W32.Native;
|
||||
|
||||
namespace CC_Functions.W32
|
||||
{
|
||||
/// <summary>
|
||||
/// Functions for manipulating the mouse
|
||||
/// </summary>
|
||||
public static class Mouse
|
||||
{
|
||||
private const int MouseEventFLeftDown = 0x02;
|
||||
private const int MouseEventFLeftUp = 0x04;
|
||||
private const int MouseEventFRightDown = 0x08;
|
||||
private const int MouseEventFRightUp = 0x10;
|
||||
|
||||
/// <summary>
|
||||
/// Emulates a click at the cursors position
|
||||
/// </summary>
|
||||
/// <param name="right">Set to true to perform right-clicks instead of left-clicks</param>
|
||||
public static void Click(bool right = false) => Click(Cursor.Position, right);
|
||||
|
||||
/// <summary>
|
||||
/// Emulates a click at the specified position
|
||||
/// </summary>
|
||||
/// <param name="location">The position to perform the click at</param>
|
||||
/// <param name="right">Set to true to perform right-clicks instead of left-clicks</param>
|
||||
public static void Click(Point location, bool right = false) =>
|
||||
user32.mouse_event(
|
||||
(uint) (right
|
||||
? MouseEventFRightDown | MouseEventFRightUp
|
||||
: MouseEventFLeftDown | MouseEventFLeftUp), (uint) location.X,
|
||||
(uint) location.Y, 0, 0);
|
||||
}
|
||||
}
|
|
@ -126,5 +126,8 @@ namespace CC_Functions.W32.Native
|
|||
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr SendMessageTimeout(IntPtr windowHandle, uint Msg, IntPtr wParam, IntPtr lParam,
|
||||
uint flags, uint timeout, out IntPtr result);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
|
||||
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
|
||||
}
|
||||
}
|
|
@ -60,6 +60,7 @@
|
|||
<Compile Include="Hooks\KeyboardHookEventArgs.cs" />
|
||||
<Compile Include="KeyboardReader.cs" />
|
||||
<Compile Include="Hooks\MouseHookEventArgs.cs" />
|
||||
<Compile Include="Mouse.cs" />
|
||||
<Compile Include="Native\advapi32.cs" />
|
||||
<Compile Include="Native\gdi32.cs" />
|
||||
<Compile Include="Native\kernel32.cs" />
|
||||
|
|
Reference in New Issue