forked from andrewkirillov/AForge.NET
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathJoystickAPI.cs
154 lines (137 loc) · 4.59 KB
/
JoystickAPI.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// AForge Controls Library
// AForge.NET framework
// http://www.aforgenet.com/framework/
//
// Copyright © Andrew Kirillov, 2010
// andrew.kirillov@aforgenet.com
//
using System;
using System.Runtime.InteropServices;
namespace AForge.Controls
{
internal static class JoystickAPI
{
[DllImport( "winmm.dll" )]
public static extern int joyGetNumDevs( );
[DllImport( "winmm.dll" )]
public static extern ResultCode joyGetDevCapsW( int uJoyID,
[In, Out, MarshalAs( UnmanagedType.LPStruct )] JOYCAPS pjc, int cbjc );
[DllImport( "winmm.dll" )]
public static extern ResultCode joyGetPos( int uJoyID, JOYINFO pji );
[DllImport( "winmm.dll" )]
public static extern ResultCode joyGetPosEx( int uJoyID, JOYINFOEX pji );
[DllImport( "winmm.dll" )]
public static extern ResultCode joyReleaseCapture( int uJoyID );
[DllImport( "winmm.dll" )]
public static extern ResultCode joySetCapture( IntPtr hwnd, int uJoyID, int uPeriod, bool fChanged );
// Information about current state of joystick's axes and buttons
[StructLayout( LayoutKind.Sequential )]
public class JOYINFO
{
public int xPos;
public int yPos;
public int zPos;
public int buttons;
}
// Extended information about current state of joystick's axes and buttons
[StructLayout( LayoutKind.Sequential )]
public class JOYINFOEX
{
public int size;
public JoyPosFlags flags;
public int xPos;
public int yPos;
public int zPos;
public int rPos;
public int uPos;
public int vPos;
public int buttons;
public int buttonNumber;
public int pov;
public int reserved1;
public int reserved2;
}
// Joystick capabilities
[StructLayout( LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode )]
public class JOYCAPS
{
public short mid;
public short pid;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst = 32 )]
public string name;
public int xMin;
public int xMax;
public int yMin;
public int yMax;
public int zMin;
public int zMax;
public int buttonsNumber;
public int minPeriod;
public int maxPeriod;
public int rMin;
public int rMax;
public int uMin;
public int uMax;
public int vMin;
public int vMax;
public int caps;
public int axesMax;
public int axesNumber;
public int buttonsMax;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst = 32 )]
public string regKey;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst = 260 )]
public string oemVxD;
}
// Some result codes
public enum ResultCode : uint
{
NoError = 0,
Error = 1,
BadDeviceID = 2,
NoDriver = 6,
InvalidParam = 11,
JoystickInvalidParam = 165,
JoystickRequestNotCompleted = 166,
JoystickUnplugged = 167
}
[Flags]
public enum JoyPosFlags
{
ReturnX = 0x01,
ReturnY = 0x02,
ReturnZ = 0x04,
ReturnR = 0x08,
ReturnU = 0x10,
ReturnV = 0x20,
ReturnPov = 0x40,
ReturnButtons = 0x80,
ReturnXY = 0x03,
ReturnXYZ = 0x07,
ReturnXYZR = 0x0F,
ReturnXYZRU = 0x1F,
ReturnXYZRUV = 0x3F,
ReturnAll = 0xFF
}
[Flags]
public enum JoyButtons
{
Button1 = 0x001,
Button2 = 0x002,
Button3 = 0x004,
Button4 = 0x008,
Button5 = 0x010,
Button6 = 0x020,
Button7 = 0x040,
Button8 = 0x080
}
public const int MM_JOY1MOVE = 0x3A0;
public const int MM_JOY2MOVE = 0x3A1;
public const int MM_JOY1ZMOVE = 0x3A2;
public const int MM_JOY2ZMOVE = 0x3A3;
public const int MM_JOY1BUTTONDOWN = 0x3B5;
public const int MM_JOY2BUTTONDOWN = 0x3B6;
public const int MM_JOY1BUTTONUP = 0x3B7;
public const int MM_JOY2BUTTONUP = 0x3B8;
}
}