1 /// Translated from C to D
2 module glfw3.xinput;
3 
4 extern(Windows): @nogc: nothrow: __gshared:
5 /*
6  * The Wine project - Xinput Joystick Library
7  * Copyright 2008 Andrew Fenn
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 import core.sys.windows.windef;
25 
26 /*
27  * Bitmasks for the joysticks buttons, determines what has
28  * been pressed on the joystick, these need to be mapped
29  * to whatever device you're using instead of an xbox 360
30  * joystick
31  */
32 
33 enum XINPUT_GAMEPAD_DPAD_UP =          0x0001;
34 enum XINPUT_GAMEPAD_DPAD_DOWN =        0x0002;
35 enum XINPUT_GAMEPAD_DPAD_LEFT =        0x0004;
36 enum XINPUT_GAMEPAD_DPAD_RIGHT =       0x0008;
37 enum XINPUT_GAMEPAD_START =            0x0010;
38 enum XINPUT_GAMEPAD_BACK =             0x0020;
39 enum XINPUT_GAMEPAD_LEFT_THUMB =       0x0040;
40 enum XINPUT_GAMEPAD_RIGHT_THUMB =      0x0080;
41 enum XINPUT_GAMEPAD_LEFT_SHOULDER =    0x0100;
42 enum XINPUT_GAMEPAD_RIGHT_SHOULDER =   0x0200;
43 enum XINPUT_GAMEPAD_A =                0x1000;
44 enum XINPUT_GAMEPAD_B =                0x2000;
45 enum XINPUT_GAMEPAD_X =                0x4000;
46 enum XINPUT_GAMEPAD_Y =                0x8000;
47 
48 /*
49  * Defines the flags used to determine if the user is pushing
50  * down on a button, not holding a button, etc
51  */
52 
53 enum XINPUT_KEYSTROKE_KEYDOWN =        0x0001;
54 enum XINPUT_KEYSTROKE_KEYUP =          0x0002;
55 enum XINPUT_KEYSTROKE_REPEAT =         0x0004;
56 
57 /*
58  * Defines the codes which are returned by XInputGetKeystroke
59  */
60 
61 enum VK_PAD_A =                        0x5800;
62 enum VK_PAD_B =                        0x5801;
63 enum VK_PAD_X =                        0x5802;
64 enum VK_PAD_Y =                        0x5803;
65 enum VK_PAD_RSHOULDER =                0x5804;
66 enum VK_PAD_LSHOULDER =                0x5805;
67 enum VK_PAD_LTRIGGER =                 0x5806;
68 enum VK_PAD_RTRIGGER =                 0x5807;
69 enum VK_PAD_DPAD_UP =                  0x5810;
70 enum VK_PAD_DPAD_DOWN =                0x5811;
71 enum VK_PAD_DPAD_LEFT =                0x5812;
72 enum VK_PAD_DPAD_RIGHT =               0x5813;
73 enum VK_PAD_START =                    0x5814;
74 enum VK_PAD_BACK =                     0x5815;
75 enum VK_PAD_LTHUMB_PRESS =             0x5816;
76 enum VK_PAD_RTHUMB_PRESS =             0x5817;
77 enum VK_PAD_LTHUMB_UP =                0x5820;
78 enum VK_PAD_LTHUMB_DOWN =              0x5821;
79 enum VK_PAD_LTHUMB_RIGHT =             0x5822;
80 enum VK_PAD_LTHUMB_LEFT =              0x5823;
81 enum VK_PAD_LTHUMB_UPLEFT =            0x5824;
82 enum VK_PAD_LTHUMB_UPRIGHT =           0x5825;
83 enum VK_PAD_LTHUMB_DOWNRIGHT =         0x5826;
84 enum VK_PAD_LTHUMB_DOWNLEFT =          0x5827;
85 enum VK_PAD_RTHUMB_UP =                0x5830;
86 enum VK_PAD_RTHUMB_DOWN =              0x5831;
87 enum VK_PAD_RTHUMB_RIGHT =             0x5832;
88 enum VK_PAD_RTHUMB_LEFT =              0x5833;
89 enum VK_PAD_RTHUMB_UPLEFT =            0x5834;
90 enum VK_PAD_RTHUMB_UPRIGHT =           0x5835;
91 enum VK_PAD_RTHUMB_DOWNRIGHT =         0x5836;
92 enum VK_PAD_RTHUMB_DOWNLEFT =          0x5837;
93 
94 /*
95  * Deadzones are for analogue joystick controls on the joypad
96  * which determine when input should be assumed to be in the
97  * middle of the pad. This is a threshold to stop a joypad
98  * controlling the game when the player isn't touching the
99  * controls.
100  */
101 
102 enum XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE =  7849;
103 enum XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE = 8689;
104 enum XINPUT_GAMEPAD_TRIGGER_THRESHOLD =    30;
105 
106 
107 /*
108  * Defines what type of abilities the type of joystick has
109  * DEVTYPE_GAMEPAD is available for all joysticks, however
110  * there may be more specific identifiers for other joysticks
111  * which are being used.
112  */
113 
114 enum XINPUT_DEVTYPE_GAMEPAD =          0x01;
115 enum XINPUT_DEVSUBTYPE_GAMEPAD =       0x01;
116 enum XINPUT_DEVSUBTYPE_WHEEL =         0x02;
117 enum XINPUT_DEVSUBTYPE_ARCADE_STICK =  0x03;
118 enum XINPUT_DEVSUBTYPE_FLIGHT_SICK =   0x04;
119 enum XINPUT_DEVSUBTYPE_DANCE_PAD =     0x05;
120 enum XINPUT_DEVSUBTYPE_GUITAR =        0x06;
121 enum XINPUT_DEVSUBTYPE_DRUM_KIT =      0x08;
122 
123 /*
124  * These are used with the XInputGetCapabilities function to
125  * determine the abilities to the joystick which has been
126  * plugged in.
127  */
128 
129 enum XINPUT_CAPS_VOICE_SUPPORTED =     0x0004;
130 enum XINPUT_FLAG_GAMEPAD =             0x00000001;
131 
132 /*
133  * Defines the status of the battery if one is used in the
134  * attached joystick. The first two define if the joystick
135  * supports a battery. Disconnected means that the joystick
136  * isn't connected. Wired shows that the joystick is a wired
137  * joystick.
138  */
139 
140 enum BATTERY_DEVTYPE_GAMEPAD =         0x00;
141 enum BATTERY_DEVTYPE_HEADSET =         0x01;
142 enum BATTERY_TYPE_DISCONNECTED =       0x00;
143 enum BATTERY_TYPE_WIRED =              0x01;
144 enum BATTERY_TYPE_ALKALINE =           0x02;
145 enum BATTERY_TYPE_NIMH =               0x03;
146 enum BATTERY_TYPE_UNKNOWN =            0xFF;
147 enum BATTERY_LEVEL_EMPTY =             0x00;
148 enum BATTERY_LEVEL_LOW =               0x01;
149 enum BATTERY_LEVEL_MEDIUM =            0x02;
150 enum BATTERY_LEVEL_FULL =              0x03;
151 
152 /*
153  * How many joysticks can be used with this library. Games that
154  * use the xinput library will not go over this number.
155  */
156 
157 enum XUSER_MAX_COUNT =                 4;
158 enum XUSER_INDEX_ANY =                 0x000000FF;
159 
160 /*
161  * Defines the structure of an xbox 360 joystick.
162  */
163 
164 struct _XINPUT_GAMEPAD {
165     WORD wButtons;
166     BYTE bLeftTrigger;
167     BYTE bRightTrigger;
168     SHORT sThumbLX;
169     SHORT sThumbLY;
170     SHORT sThumbRX;
171     SHORT sThumbRY;
172 }
173 alias _XINPUT_GAMEPAD XINPUT_GAMEPAD;
174 alias _XINPUT_GAMEPAD* PXINPUT_GAMEPAD;
175 
176 struct _XINPUT_STATE {
177     DWORD dwPacketNumber;
178     XINPUT_GAMEPAD Gamepad;
179 }
180 alias _XINPUT_STATE XINPUT_STATE;
181 alias _XINPUT_STATE* PXINPUT_STATE;
182 
183 /*
184  * Defines the structure of how much vibration is set on both the
185  * right and left motors in a joystick. If you're not using a 360
186  * joystick you will have to map these to your device.
187  */
188 
189 struct _XINPUT_VIBRATION {
190     WORD wLeftMotorSpeed;
191     WORD wRightMotorSpeed;
192 }
193 alias _XINPUT_VIBRATION XINPUT_VIBRATION;
194 alias _XINPUT_VIBRATION* PXINPUT_VIBRATION;
195 
196 /*
197  * Defines the structure for what kind of abilities the joystick has
198  * such abilities are things such as if the joystick has the ability
199  * to send and receive audio, if the joystick is in fact a driving
200  * wheel or perhaps if the joystick is some kind of dance pad or
201  * guitar.
202  */
203 
204 struct _XINPUT_CAPABILITIES {
205     BYTE Type;
206     BYTE SubType;
207     WORD Flags;
208     XINPUT_GAMEPAD Gamepad;
209     XINPUT_VIBRATION Vibration;
210 }
211 alias _XINPUT_CAPABILITIES XINPUT_CAPABILITIES;
212 alias _XINPUT_CAPABILITIES* PXINPUT_CAPABILITIES;
213 
214 /*
215  * Defines the structure for a joystick input event which is
216  * retrieved using the function XInputGetKeystroke
217  */
218 struct _XINPUT_KEYSTROKE {
219     WORD VirtualKey;
220     WCHAR Unicode;
221     WORD Flags;
222     BYTE UserIndex;
223     BYTE HidCode;
224 }
225 alias _XINPUT_KEYSTROKE XINPUT_KEYSTROKE;
226 alias _XINPUT_KEYSTROKE* PXINPUT_KEYSTROKE;
227 
228 struct _XINPUT_BATTERY_INFORMATION {
229     BYTE BatteryType;
230     BYTE BatteryLevel;
231 }
232 alias _XINPUT_BATTERY_INFORMATION XINPUT_BATTERY_INFORMATION;
233 alias _XINPUT_BATTERY_INFORMATION* PXINPUT_BATTERY_INFORMATION;
234 
235 import core.sys.windows.basetyps: GUID;
236 
237 void XInputEnable(WINBOOL);
238 DWORD XInputSetState(DWORD, XINPUT_VIBRATION*);
239 DWORD XInputGetState(DWORD, XINPUT_STATE*);
240 DWORD XInputGetKeystroke(DWORD, DWORD, PXINPUT_KEYSTROKE);
241 DWORD XInputGetCapabilities(DWORD, DWORD, XINPUT_CAPABILITIES*);
242 DWORD XInputGetDSoundAudioDeviceGuids(DWORD, GUID*, GUID*);
243 DWORD XInputGetBatteryInformation(DWORD, BYTE, XINPUT_BATTERY_INFORMATION*);