coastline 0.0.4
Loading...
Searching...
No Matches
input.h
Go to the documentation of this file.
1#pragma once
2
7
8#ifndef DIRECTINPUT_VERSION
10#define DIRECTINPUT_VERSION 0x0500
11#endif
12#include <windows.h>
13// The headers below need the types of windows.h.
14#include <dinput.h>
15
17#include "common/inputbinding.h"
18#include "common/inputpoll.h"
19
22private:
23 int nCursorX;
24 int nCursorY;
25 int nWheel;
26 int nPrevCursorX;
27 int nPrevCursorY;
28 [[maybe_unused]] char abUnknown14[0x10]; /* +0x14 */
29 unsigned char abButtons[4];
30 unsigned char abPrevButtons[4];
31 int abHeld[4];
32 int abClicked[4];
33 int bPressPending;
34 IDirectInputDeviceA *pDevice;
35
36public:
38 int GetCursorX() const {
39 return nCursorX;
40 }
41
42 int GetCursorY() const {
43 return nCursorY;
44 }
45
46 int GetPreviousCursorY() const {
47 return nPrevCursorY;
48 }
49
50 void SetCursorX(int value) {
51 nCursorX = value;
52 }
53
54 void SetCursorY(int value) {
55 nCursorY = value;
56 }
57
58 bool IsButtonHeld(int index) const {
59 return abHeld[index] != 0;
60 }
61
63 return pDevice;
64 }
65
73
84
92
104
114};
115
122extern int g_fHostWindowActive;
123
134
141extern int g_fCharInputSuppressed;
142
149extern short g_dwMouseScrollDirection;
150
157extern unsigned short g_wMenuHoverIndex;
158
166
174
175#ifdef __cplusplus
176extern "C" {
177#endif
178
186
197int ShowInfoMessageBox(HWND hWnd, HRESULT hResult, const char *pszText);
198
208
217
231 IDirectInputDevice2A *pDevice, REFGUID guidProperty, DWORD dwObject, DWORD dwHow, DWORD dwData);
232
247 REFGUID guidProperty,
248 DWORD dwObject,
249 DWORD dwHow,
250 LONG lMin,
251 LONG lMax);
252
260
269
278
280#define KEYBOARD_KEY_COUNT 256
281
292
301unsigned char IsInputBindingPressed(int nBinding);
302
311unsigned char IsInputBindingHeld(int nBinding);
312
318extern int g_anMouseAxisRanges[8];
319
326extern unsigned char g_abKeyboardState[KEYBOARD_KEY_COUNT];
327
335
337#define MOUSE_BUTTON_COUNT 4
338
346
354
362
370
380
382#define JOYSTICK_CONTROL_BUTTON 0x100
384#define JOYSTICK_CONTROL_X_NEGATIVE 0x8000
386#define JOYSTICK_CONTROL_X_POSITIVE 0x8100
388#define JOYSTICK_CONTROL_Y_NEGATIVE 0x8200
390#define JOYSTICK_CONTROL_Y_POSITIVE 0x8300
391
394 int nCode;
395 char szName[32];
396};
397
399#define JOYSTICK_NAME_COUNT_A 10
401#define JOYSTICK_NAME_COUNT_B 134
402
410
418
420#define KEYBOARD_CONTROL_NAME_COUNT 120
421
429
439int FindControlNameIndex(int nTable, int nCode);
440
450
459
470int GetPressedJoystickControl(unsigned *pwControl);
471
482
492HRESULT ReadKeyboardState(unsigned char *pabState);
493
502
510
518
528
536
547HRESULT CreateForceFeedbackEffects(int nCoefficientX, int nCoefficientY);
548
561 void *pContext);
562
571
579
589int GetFirstPressedKeyIndex(char *pszKeyName = nullptr);
590
600
609#ifdef __cplusplus
610}
611#endif
The mouse of the game.
Definition input.h:21
void SetCursorY(int value)
Set the vertical cursor position.
Definition input.h:54
void ReleaseMouseDevice()
Unacquire and release the DirectInput device of the mouse.
MouseDevice()
Clear the state of the mouse.
bool CreateMouseDevice(HWND hWnd)
Create the DirectInput device of the system mouse for a window, in the format of a mouse and with exc...
int GetCursorY() const
Definition input.h:42
void SyncMouseAcquireState(HWND hWnd)
Acquire the mouse while the game window is active and release it while another window is active.
void SetCursorX(int value)
Set the horizontal cursor position.
Definition input.h:50
void PollMouseDevice(HWND hWnd)
Read the mouse and the arrows of the keyboard for the menus.
int GetPreviousCursorY() const
Definition input.h:46
int GetCursorX() const
Definition input.h:38
bool IsButtonHeld(int index) const
Definition input.h:58
IDirectInputDeviceA * GetDirectInputDevice() const
Definition input.h:62
The bindings of the controls of the game, which the settings save.
typedef REFGUID
A control and its label in the menus.
Definition input.h:393
int nCode
Definition input.h:394
char szName[32]
Definition input.h:395
Mouse axes, accumulated movement, and buttons from input polling.
Definition input.h:283
LONG lZ
Definition input.h:286
LONG lX
Definition input.h:284
LONG lAccumulatedX
Definition input.h:287
LONG lY
Definition input.h:285
LONG lAccumulatedZ
Definition input.h:289
LONG lAccumulatedY
Definition input.h:288
unsigned char abButtons[4]
Definition input.h:290
The state of the menus the mouse and the arrows of the keyboard move.
Definition input.h:125
DWORD dwScrollRepeatTimerMs
Definition input.h:132
int bScrollDecPending
Definition input.h:126
DWORD dwPollLastTimeMs
Definition input.h:131
int bScrollRepeatReady
Definition input.h:130
int bKeyLeftAsButton0
Definition input.h:128
int bKeyRightAsButton1
Definition input.h:129
int bScrollIncPending
Definition input.h:127
unsigned char IsInputBindingPressed(int nBinding)
Read rising edges of an active binding and its keyboard alternatives.
int FindControlNameIndex(int nTable, int nCode)
Find a control code in the keyboard or joystick label table.
void InitJoystickBindingNames(void)
Fill the names of the controls of a game controller.
int GetPressedMouseButton(void)
Read the buttons of the mouse and find the first one that went down.
int g_adwKeyPressedEdge[KEYBOARD_KEY_COUNT]
Whether each key went down since the keyboard was read before.
void PollKeyboardState(void)
Read the keyboard into g_abKeyboardState and find the keys that went down.
#define JOYSTICK_NAME_COUNT_B
The number of entries of g_aJoystickButtonNamesB.
Definition input.h:401
HRESULT SetJoystickPropertyDword(IDirectInputDevice2A *pDevice, REFGUID guidProperty, DWORD dwObject, DWORD dwHow, DWORD dwData)
Set a property of a DIPROPDWORD on a DirectInput device.
int ShowInfoMessageBox(HWND hWnd, HRESULT hResult, const char *pszText)
Show a message of the input with the caption of string 0xaa.
int GetPressedJoystickControl(unsigned *pwControl)
Read the game controller and find a control that is pressed, to bind it.
#define KEYBOARD_CONTROL_NAME_COUNT
The number of keyboard control labels.
Definition input.h:420
unsigned char IsInputBindingHeld(int nBinding)
Read an active binding and its keyboard alternatives.
void SetForceFeedbackMagnitude(LONG lMagnitude)
Set both coefficients of the first spring of g_DiConditionEffect, and give the effect its new paramet...
void ClearKeyboardStateBuffers(void)
Clear the state of the keyboard.
HRESULT ReadKeyboardState(unsigned char *pabState)
Read the state of the keyboard, acquiring the device again and reading once more when the input was l...
#define MOUSE_BUTTON_COUNT
The number of buttons of the mouse the game reads.
Definition input.h:337
InputControlName g_aJoystickButtonNamesB[JOYSTICK_NAME_COUNT_B]
The names of 128 buttons and six axes of a game controller.
int g_fHostWindowActive
Whether the game window has focus and can receive input.
bool InitializeKeyboardDevice(void)
Add a user of the keyboard.
#define KEYBOARD_KEY_COUNT
The number of keys of the state of a keyboard.
Definition input.h:280
void UpdateKeyboardEdgeState(void)
Find the keys that went down since the keyboard was read before.
int GetFirstPressedKeyIndex(char *pszKeyName=nullptr)
The first key of g_adwKeyPressedEdge pressed in this frame.
short g_dwMouseScrollDirection
The direction the hover of a menu moved last, -1 up and 1 down.
void UpdateMouseButtonEdges(void)
Find the buttons of the mouse that went down since the mouse was read before.
unsigned char g_abKeyboardState[KEYBOARD_KEY_COUNT]
The keys of the keyboard the game read last, as DirectInput reports them.
bool CheckForUserInput(void)
Whether a key or a button of the mouse was pressed in this frame.
HRESULT SetJoystickAxisRange(IDirectInputDevice2A *pDevice, REFGUID guidProperty, DWORD dwObject, DWORD dwHow, LONG lMin, LONG lMax)
Set a property of a DIPROPRANGE on a DirectInput device.
bool WINAPI ResetMouseCursorToCenter(HWND hWnd)
Put the cursor of the mouse in the centre of the screen and clear g_MouseMenuState.
int g_adwMouseButtonPressed[MOUSE_BUTTON_COUNT]
Whether each button of the mouse went down since the mouse was read before.
bool IsInputOrEventActive(void)
Whether a button of the mouse was pressed or, outside the setup of the car of network play,...
HRESULT CreateForceFeedbackEffects(int nCoefficientX, int nCoefficientY)
Create the condition effect, a spring on X and Y that lasts until it stops, and the jolt effect,...
MouseDevice * g_pMouseDevice
The mouse, created with DirectInput.
int g_anMouseAxisRanges[8]
Movement ranges for the eight mouse sensitivity settings.
int g_adwMouseButtonRaw[MOUSE_BUTTON_COUNT]
Whether each button of the mouse is down.
void PollInputAndUpdateEdges(void)
Refresh keyboard and mouse button transitions for menu input.
unsigned short g_wMenuHoverIndex
The item of a menu under the hover.
#define JOYSTICK_NAME_COUNT_A
The number of entries of g_aJoystickButtonNamesA.
Definition input.h:399
InputControlName g_aKeyboardControlNames[KEYBOARD_CONTROL_NAME_COUNT]
The labels of the keyboard controls available for binding.
int g_fCharInputSuppressed
Whether the input of characters is held back, which stops the poll of the mouse.
DWORD g_dwLastInputActivityTime
The time of the last change of the mouse, in milliseconds.
MouseDevice * g_pMousePosition
The mouse that was read last.
void ProbeJoystickDevice(void)
Create and release the first game controller with force feedback on, to find whether one is attached.
InputControlName g_aJoystickButtonNamesA[JOYSTICK_NAME_COUNT_A]
The names of four buttons and six axes of a game controller.
bool ShutdownDirectInput(void)
Drop a user of DirectInput.
void ReleaseKeyboardDevice(void)
Drop a user of the keyboard device.
void UpdateMouseInput(void)
Read the mouse for the main window.
BOOL CALLBACK EnumJoysticksCallback_CreateDevice(const DIDEVICEINSTANCEA *pInstance, void *pContext)
Create the device of the first attached game controller DirectInput enumerates, as its second interfa...
LONG g_adwForceFeedbackDirection[2]
The direction of the jolt, along the negative X axis.
int g_bForceFeedbackAvailable
Whether the game controller has force feedback.
bool InitializeDirectInput(void)
Add a user of DirectInput.
bool TryAcquireJoystickDevice(void)
Acquire the DirectInput device of the game controller.
typedef BOOL
typedef CALLBACK
typedef DWORD
typedef HRESULT
typedef HWND
typedef LONG
typedef WINAPI