-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMouseHider.cs
67 lines (60 loc) · 2.04 KB
/
MouseHider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using Biotronic;
using System;
using System.Linq;
namespace ImmersiveGaming
{
public static partial class MouseHider
{
static bool shown = true;
static uint[] cursorIds;
static IntPtr[] OriginalCursors;
static IntPtr[] blankCursors;
static MouseHider()
{
cursorIds = Enums.Values<User32Types.CursorName>().Cast<uint>().ToArray();
OriginalCursors = new IntPtr[cursorIds.Length];
blankCursors = new IntPtr[cursorIds.Length];
int i = 0;
var blank = User32.CreateCursor(IntPtr.Zero, 0, 0, 32, 32, ((byte)0xFF).Repeat(32 * 4).ToArray(), ((byte)0x00).Repeat(32 * 4).ToArray());
foreach (var cursor in cursorIds)
{
var hc = User32.LoadCursor(IntPtr.Zero, (IntPtr)cursor);
OriginalCursors[i] = User32.CopyImage(hc, 2, 0, 0, 0);
blankCursors[i] = blank;
i++;
}
AppDomain.CurrentDomain.ProcessExit += OnProcessExit;
}
static void OnProcessExit(object sender, EventArgs e)
{
ShowCursors();
}
private static void UpdateCursors(IntPtr[] cursors)
{
int i = 0;
foreach (var cursor in cursorIds)
{
var hc = User32.CopyImage(cursors[i], 2, 0, 0, 0);
User32.SetSystemCursor(hc, (UInt32)cursor);
}
}
public static void HideCursors()
{
if (shown)
{
UpdateCursors(blankCursors);
shown = false;
}
}
public static void ShowCursors()
{
if (!shown)
{
UpdateCursors(OriginalCursors);
shown = true;
User32.SystemParametersInfo(User32Types.SPI.SPI_SETCURSORS, 0, IntPtr.Zero, User32Types.SPIF.SPIF_UPDATEINIFILE);
//SystemParametersInfo(SPI_SETCURSORS, 0, 0, WM_SETTINGCHANGE | SPIF_UPDATEINIFILE );
}
}
}
}