Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions WindowsInput/IInputDeviceStateAdaptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,15 @@ public interface IInputDeviceStateAdaptor
/// <c>true</c> if the toggling key is toggled on (in-effect); otherwise, <c>false</c>.
/// </returns>
bool IsTogglingKeyInEffect(VirtualKeyCode keyCode);

/// <summary>
/// Gets the current state of the mouse cursor.
/// </summary>
CursorFlag GetCursorFlag();

/// <summary>
/// Gets the current screen coordinates of the mouse cursor.
/// </summary>
Point GetCursorScreenCoordinates();
}
}
32 changes: 32 additions & 0 deletions WindowsInput/Native/CURSORINFO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;

namespace WindowsInput.Native
{
#pragma warning disable 649
/// <summary>
/// Contains global cursor information. See: (https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-cursorinfo)
/// </summary>
public struct CURSORINFO
{
/// <summary>
/// The size of the structure in bytes. The caller must set this to sizeof(CURSORINFO).
/// </summary>
public Int32 cbSize;

/// <summary>
/// The cursor state. This parameter can be one of the following values.
/// </summary>
public CursorFlag flags;

/// <summary>
/// A handle to the cursor.
/// </summary>
public IntPtr hCursor;

/// <summary>
/// The structure that receives the screen coordinates of the cursor.
/// </summary>
public Point ptScreenPos;
}
#pragma warning restore 649
}
26 changes: 26 additions & 0 deletions WindowsInput/Native/CursorFlag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;

namespace WindowsInput.Native
{
/// <summary>
/// The cursor state. CursorFlag is a part of CURSORINFO structure (DWORD flags) (winuser.h). (See: https://docs.microsoft.com/ru-ru/windows/win32/api/winuser/ns-winuser-cursorinfo)
/// </summary>
[Flags]
public enum CursorFlag : Int32
{
/// <summary>
/// The cursor is hidden.
/// </summary>
Hidden = 0x0000,

/// <summary>
/// The cursor is showing.
/// </summary>
Visible = 0x0001,

/// <summary>
/// Windows 8: The cursor is suppressed. This flag indicates that the system is not drawing the cursor because the user is providing input through touch or pen instead of the mouse.
/// </summary>
Suppressed = 0x002
}
}
8 changes: 8 additions & 0 deletions WindowsInput/Native/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,13 @@ internal static class NativeMethods
/// <returns></returns>
[DllImport("user32.dll")]
public static extern UInt32 MapVirtualKey(UInt32 uCode, UInt32 uMapType);

/// <summary>
/// Retrieves information about the global cursor.
/// </summary>
/// <param name="cursorInfo"></param>
/// <returns></returns>
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetCursorInfo(ref CURSORINFO cursorInfo);
}
}
31 changes: 31 additions & 0 deletions WindowsInput/Native/Point.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Runtime.InteropServices;

namespace WindowsInput.Native
{
/// <summary>
/// The structure that receives the screen coordinates of the cursor. See: (https://docs.microsoft.com/en-us/previous-versions/dd162805(v=vs.85)
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public readonly struct Point
{
/// <summary>
/// Make a point with the specified coordinates.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
public Point(int x, int y)
{
X = x;
Y = y;
}

/// <summary>
/// The X coordinate of mouse cursor on virtual desktop.
/// </summary>
public readonly int X;
/// <summary>
/// The Y coordinate of mouse cursor on virtual desktop.
/// </summary>
public readonly int Y;
}
}
3 changes: 3 additions & 0 deletions WindowsInput/WindowsInput.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
<Compile Include="InputSimulator.cs" />
<Compile Include="MouseButton.cs" />
<Compile Include="MouseSimulator.cs" />
<Compile Include="Native\CursorFlag.cs" />
<Compile Include="Native\CURSORINFO.cs" />
<Compile Include="Native\NativeMethods.cs" />
<Compile Include="Native\HARDWAREINPUT.cs" />
<Compile Include="IInputDeviceStateAdaptor.cs" />
Expand All @@ -71,6 +73,7 @@
<Compile Include="Native\MouseFlag.cs" />
<Compile Include="Native\MOUSEINPUT.cs" />
<Compile Include="Native\MOUSEKEYBDHARDWAREINPUT.cs" />
<Compile Include="Native\Point.cs" />
<Compile Include="WindowsInputDeviceStateAdaptor.cs" />
<Compile Include="WindowsInputMessageDispatcher.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
42 changes: 42 additions & 0 deletions WindowsInput/WindowsInputDeviceStateAdaptor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Runtime.InteropServices;
using WindowsInput.Native;

namespace WindowsInput
Expand Down Expand Up @@ -153,5 +154,46 @@ public bool IsTogglingKeyInEffect(VirtualKeyCode keyCode)
Int16 result = NativeMethods.GetKeyState((UInt16)keyCode);
return (result & 0x01) == 0x01;
}

/// <summary>
/// The cursor state. CursorFlag is a part of CURSORINFO structure (DWORD flags) (winuser.h). (See: https://docs.microsoft.com/ru-ru/windows/win32/api/winuser/ns-winuser-cursorinfo)
/// </summary>
/// <returns>
/// <c>Hidden</c> if the cursor is hidden.
/// <c>Visible</c> if the cursor is showing.
/// <c>Suppressed</c> Windows 8: The cursor is suppressed. This flag indicates that the system is not drawing the cursor because the user is providing input through touch or pen instead of the mouse.
/// </returns>
public CursorFlag GetCursorFlag()
{
return GetCursorInfo().flags;
}

/// <summary>
/// The structure that receives the screen coordinates of the cursor.
/// </summary>
/// <returns>
/// <c>Point</c> The X and Y coordinates of cursor position on screen.
/// </returns>
public Point GetCursorScreenCoordinates()
{
return GetCursorInfo().ptScreenPos;
}

/// <summary>
/// Contains global cursor information. See: (https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-cursorinfo)
/// </summary>
/// <returns>
/// <c>cbSize</c> The size of the structure, in bytes.
/// <c>flags</c> The cursor state. This parameter can be one of the following values.
/// <c>hCursor</c> A handle to the cursor.
/// <c>ptScreenPos</c> The structure that receives the screen coordinates of the cursor.
/// </returns>
private static CURSORINFO GetCursorInfo()
{
CURSORINFO cursorInfo = new CURSORINFO();
cursorInfo.cbSize = Marshal.SizeOf(cursorInfo);
NativeMethods.GetCursorInfo(ref cursorInfo);
return cursorInfo;
}
}
}