UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
InputState.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "InputCoreTypes.h"
8#include "Math/Ray.h"
9#include "Math/UnrealMath.h"
10#include "Math/UnrealMathSSE.h"
11#include "Math/Vector.h"
12#include "Math/Vector2D.h"
14#include "Misc/EnumClassFlags.h"
18
19#include "InputState.generated.h"
20
21class UObject;
22
23
28UENUM()
30{
31 None = 0,
32 Keyboard = 1,
33 Mouse = 2,
34 Gamepad = 4,
35
36 OculusTouch = 8,
37 HTCViveWands = 16,
39
40 TabletFingers = 1024
41};
43
44
45
46/*
47 * FInputRayHit is returned by various hit-test interface functions.
48 * Generally this is intended to be returned as the result of a hit-test with a FInputDeviceRay
49 */
50USTRUCT(BlueprintType)
52{
54
55
56 UPROPERTY(BlueprintReadWrite, Category = InputRayHit)
57 bool bHit;
58
60 UPROPERTY(BlueprintReadWrite, Category = InputRayHit)
61 double HitDepth;
62
64 UPROPERTY(BlueprintReadWrite, Category = InputRayHit)
65 FVector HitNormal;
66
68 UPROPERTY(BlueprintReadWrite, Category = InputRayHit)
69 bool bHasHitNormal;
70
72 UPROPERTY(BlueprintReadWrite, Category = InputRayHit)
73 int32 HitIdentifier;
74
79 void* HitOwner;
80
85 UPROPERTY(BlueprintReadWrite, Category = InputRayHit)
87
89 void SetHitObject(UObject* InHitObject)
90 {
91 HitObject = InHitObject;
92 HitOwner = InHitObject;
93 }
94
96 {
97 bHit = false;
99 HitNormal = FVector(0, 0, 1);
100 bHasHitNormal = false;
101 HitIdentifier = 0;
102 HitOwner = nullptr;
103 HitObject = nullptr;
104 }
105
106 explicit FInputRayHit(double HitDepthIn)
107 {
108 bHit = true;
109 HitDepth = HitDepthIn;
110 HitNormal = FVector(0, 0, 1);
111 bHasHitNormal = false;
112 HitIdentifier = 0;
113 HitOwner = nullptr;
114 HitObject = nullptr;
115 }
116
118 {
119 bHit = true;
120 HitDepth = HitDepthIn;
121 HitNormal = HitNormalIn;
122 bHasHitNormal = true;
123 HitIdentifier = 0;
124 HitOwner = nullptr;
125 HitObject = nullptr;
126 }
127
128};
129
130
131
132
133
142USTRUCT(BlueprintType)
144{
146
147
148 UPROPERTY(transient, BlueprintReadWrite, Category = DeviceButtonState)
150
152 UPROPERTY(transient, BlueprintReadWrite, Category = DeviceButtonState)
153 bool bPressed;
154
156 UPROPERTY(transient, BlueprintReadWrite, Category = DeviceButtonState)
157 bool bDown;
158
160 UPROPERTY(transient, BlueprintReadWrite, Category = DeviceButtonState)
161 bool bReleased;
162
164 UPROPERTY(Transient, BlueprintReadWrite, Category = DeviceButtonState)
165 bool bDoubleClicked;
166
168 {
169 Button = FKey();
170 bPressed = bDown = bReleased = bDoubleClicked = false;
171 }
172
174 {
176 bPressed = bDown = bReleased = bDoubleClicked = false;
177 }
178
180 void SetStates(bool bPressedIn, bool bDownIn, bool bReleasedIn, bool bDoubleClickedIn = false)
181 {
182 bPressed = bPressedIn;
183 bDown = bDownIn;
184 bReleased = bReleasedIn;
185 bDoubleClicked = bDoubleClickedIn;
186 }
187};
188
189
190
195USTRUCT(BlueprintType)
197{
199
200
201 UPROPERTY(transient, BlueprintReadWrite, Category = KeyboardInputDeviceState)
203};
204
205
206
210USTRUCT(BlueprintType)
212{
214
215
216 UPROPERTY(transient, BlueprintReadWrite, Category = MouseInputDeviceState)
218
220 UPROPERTY(transient, BlueprintReadWrite, Category = MouseInputDeviceState)
222
224 UPROPERTY(transient, BlueprintReadWrite, Category = MouseInputDeviceState)
226
228 UPROPERTY(transient, BlueprintReadWrite, Category = MouseInputDeviceState)
229 float WheelDelta;
230
232 UPROPERTY(transient, BlueprintReadWrite, Category = MouseInputDeviceState)
233 FVector2D Position2D;
234
236 UPROPERTY(transient, BlueprintReadWrite, Category = MouseInputDeviceState)
237 FVector2D Delta2D;
238
240 UPROPERTY(transient, BlueprintReadWrite, Category = MouseInputDeviceState)
241 FRay WorldRay;
242
253};
254
255
256
262USTRUCT(BlueprintType)
264{
266
267
268 UPROPERTY(transient, BlueprintReadWrite, Category = MouseInputDeviceState)
270
271 //
272 // keyboard modifiers
273 //
274
276 UPROPERTY(transient, BlueprintReadWrite, Category = MouseInputDeviceState)
277 bool bShiftKeyDown;
278
280 UPROPERTY(transient, BlueprintReadWrite, Category = MouseInputDeviceState)
281 bool bAltKeyDown;
282
284 UPROPERTY(transient, BlueprintReadWrite, Category = MouseInputDeviceState)
285 bool bCtrlKeyDown;
286
288 UPROPERTY(transient, BlueprintReadWrite, Category = MouseInputDeviceState)
289 bool bCmdKeyDown;
290
292 UPROPERTY(transient, BlueprintReadWrite, Category = MouseInputDeviceState)
294
296 UPROPERTY(transient, BlueprintReadWrite, Category = MouseInputDeviceState)
298
300 {
302 bShiftKeyDown = bAltKeyDown = bCtrlKeyDown = bCmdKeyDown = false;
305 }
306
309 {
310 bShiftKeyDown = bShiftDown;
311 bAltKeyDown = bAltDown;
312 bCtrlKeyDown = bCtrlDown;
313 bCmdKeyDown = bCmdDown;
314 }
315
320 bool IsFromDevice(EInputDevices DeviceType) const
321 {
322 return ((InputDevice & DeviceType) != EInputDevices::None);
323 }
324
325
326
327
328 //
329 // utility functions to pass as lambdas
330 //
331
334 {
335 return InputState.bShiftKeyDown;
336 }
337
340 {
341 return InputState.bCtrlKeyDown;
342 }
343
346 {
347 return InputState.bAltKeyDown;
348 }
349
352 {
353 return InputState.bCmdKeyDown;
354 }
355};
356
357
358
359
365USTRUCT(BlueprintType)
367{
369
370
371 UPROPERTY(transient, BlueprintReadWrite, Category = InputDeviceRay)
372 FRay WorldRay;
373
375 UPROPERTY(transient, BlueprintReadWrite, Category = InputDeviceRay)
376 bool bHas2D = false;
377
379 UPROPERTY(transient, BlueprintReadWrite, Category = InputDeviceRay)
381
382 // this is required for a USTRUCT
384 {
385 WorldRay = FRay();
386 bHas2D = false;
388 }
389
391 {
392 WorldRay = WorldRayIn;
393 bHas2D = false;
395 }
396
398 {
399 WorldRay = WorldRayIn;
400 bHas2D = true;
402 }
403
405 {
406 if (Input.IsFromDevice(EInputDevices::Mouse))
407 {
408 WorldRay = Input.Mouse.WorldRay;
409 bHas2D = true;
410 ScreenPosition = Input.Mouse.Position2D;
411 }
412 else
413 {
414 ensure(false);
415 WorldRay = FRay(FVector::ZeroVector, FVector(0, 0, 1), true);
417 bHas2D = false;
418 }
419 }
420};
421
422
#define ensure( InExpression)
Definition AssertionMacros.h:464
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define ENUM_CLASS_FLAGS(Enum)
Definition EnumClassFlags.h:6
#define FVector
Definition IOSSystemIncludes.h:8
EInputDevices
Definition InputState.h:30
UE::Math::TVector2< double > FVector2D
Definition MathFwd.h:48
UE::Math::TRay< double > FRay
Definition MathFwd.h:58
const bool
Definition NetworkReplayStreaming.h:178
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UENUM(...)
Definition ObjectMacros.h:749
#define USTRUCT(...)
Definition ObjectMacros.h:746
Definition InputDevice.Build.cs:6
Definition Object.h:95
@ false
Definition radaudio_common.h:23
static INPUTCORE_API const FKey RightMouseButton
Definition InputCoreTypes.h:301
static INPUTCORE_API const FKey LeftMouseButton
Definition InputCoreTypes.h:300
static INPUTCORE_API const FKey MiddleMouseButton
Definition InputCoreTypes.h:302
Definition InputState.h:144
void SetStates(bool bPressedIn, bool bDownIn, bool bReleasedIn, bool bDoubleClickedIn=false)
Definition InputState.h:180
FDeviceButtonState(const FKey &ButtonIn)
Definition InputState.h:173
Definition InputState.h:367
FInputDeviceRay(const FRay &WorldRayIn, const FVector2D &ScreenPositionIn)
Definition InputState.h:397
FInputDeviceRay(const FInputDeviceState &Input)
Definition InputState.h:404
FInputDeviceRay(const FRay &WorldRayIn)
Definition InputState.h:390
Definition InputState.h:264
void SetModifierKeyStates(bool bShiftDown, bool bAltDown, bool bCtrlDown, bool bCmdDown)
Definition InputState.h:308
static bool IsAltKeyDown(const FInputDeviceState &InputState)
Definition InputState.h:345
bool IsFromDevice(EInputDevices DeviceType) const
Definition InputState.h:320
static bool IsCmdKeyDown(const FInputDeviceState &InputState)
Definition InputState.h:351
static bool IsShiftKeyDown(const FInputDeviceState &InputState)
Definition InputState.h:333
static bool IsCtrlKeyDown(const FInputDeviceState &InputState)
Definition InputState.h:339
Definition InputState.h:52
FInputRayHit()
Definition InputState.h:95
FInputRayHit(double HitDepthIn)
Definition InputState.h:106
FInputRayHit(double HitDepthIn, const FVector &HitNormalIn)
Definition InputState.h:117
Definition InputCoreTypes.h:50
Definition InputState.h:197
Definition InputState.h:212
Definition NumericLimits.h:41
Definition WeakObjectPtrTemplates.h:25
static CORE_API const TVector2< double > ZeroVector
Definition Vector2D.h:63
static CORE_API const TVector< double > ZeroVector
Definition Vector.h:79