1
+ using System ;
2
+ using System . Numerics ;
3
+ using System . Runtime . InteropServices ;
4
+ using OpenTabletDriver . Plugin . Platform . Display ;
5
+
6
+ namespace VoiDPlugins . OutputMode
7
+ {
8
+ [ StructLayout ( LayoutKind . Sequential ) ]
9
+ public struct INPUT
10
+ {
11
+ public INPUT_TYPE type ;
12
+ public MOUSEINPUT mouse ;
13
+ public static int Size => Marshal . SizeOf ( typeof ( INPUT ) ) ;
14
+ }
15
+
16
+ [ StructLayout ( LayoutKind . Sequential ) ]
17
+ public struct MOUSEINPUT
18
+ {
19
+ public int dx ;
20
+ public int dy ;
21
+ public uint mouseData ;
22
+ public MOUSEEVENTF dwFlags ;
23
+ public uint time ;
24
+ public UIntPtr dwExtraInfo ;
25
+ }
26
+
27
+ public enum MOUSEEVENTF : uint
28
+ {
29
+ ABSOLUTE = 0x8000 ,
30
+ MOVE = 0x0001 ,
31
+ VIRTUALDESK = 0x4000 ,
32
+ LEFTDOWN = 0x0002 ,
33
+ LEFTUP = 0x0004 ,
34
+ MIDDLEDOWN = 0x0020 ,
35
+ MIDDLEUP = 0x0040 ,
36
+ RIGHTDOWN = 0x0008 ,
37
+ RIGHTUP = 0x0010 ,
38
+ XDOWN = 0x0080 ,
39
+ XUP = 0x0100 ,
40
+ MOVE_NOCOALESCE = 0x2000
41
+ }
42
+
43
+ public enum INPUT_TYPE
44
+ {
45
+ MOUSE_INPUT ,
46
+ KEYBD_INPUT ,
47
+ HARDWARE_INPUT
48
+ }
49
+
50
+ public class ThinOSPointer
51
+ {
52
+ private readonly Vector2 _conversion ;
53
+ private readonly INPUT [ ] _inputs = new INPUT [ ]
54
+ {
55
+ new INPUT
56
+ {
57
+ type = INPUT_TYPE . MOUSE_INPUT ,
58
+ mouse = new MOUSEINPUT
59
+ {
60
+ time = 0 ,
61
+ dwExtraInfo = UIntPtr . Zero
62
+ }
63
+ }
64
+ } ;
65
+
66
+ public ThinOSPointer ( IVirtualScreen screen )
67
+ {
68
+ _conversion = new Vector2 ( screen . Width , screen . Height ) / 65535 ;
69
+ }
70
+
71
+ public void SetPosition ( Vector2 pos )
72
+ {
73
+ var converted = pos / _conversion ;
74
+
75
+ _inputs [ 0 ] . mouse . dwFlags = MOUSEEVENTF . ABSOLUTE | MOUSEEVENTF . MOVE | MOUSEEVENTF . VIRTUALDESK ;
76
+ _inputs [ 0 ] . mouse . dx = ( int ) converted . X ;
77
+ _inputs [ 0 ] . mouse . dy = ( int ) converted . Y ;
78
+ _ = SendInput ( 1 , _inputs , INPUT . Size ) ;
79
+ }
80
+
81
+ [ DllImport ( "user32.dll" ) ]
82
+ private static extern uint SendInput ( uint nInputs , [ MarshalAs ( UnmanagedType . LPArray ) , In ] INPUT [ ] pInputs , int cbSize ) ;
83
+ }
84
+ }
0 commit comments