-
-
Notifications
You must be signed in to change notification settings - Fork 7
Input interface
The input interface allows you to check and control input events. The Input class can be seen below:
class Input
{
static uint8_t getKey(uint16_t key) noexcept;
static const InputAction& getAction(const UImGui::FString& name) noexcept;
static std::vector<InputAction>& getActions() noexcept;
static FVector2 getMousePositionChange() noexcept;
static FVector2 getCurrentMousePosition() noexcept;
static FVector2 getLastMousePosition() noexcept;
static FVector2 getScroll() noexcept;
};The following functions can be used to track mouse movements:
getMousePositionChangegetCurrentMousePositiongetLastMousePositiongetScroll
These functions return 2D vectors, where X is left/right and Y is up/down/forward/backward.
The following functions can be used to track keyboard + some mouse key events
getKeygetActiongetActions
The getKey function takes a key code for which to return an event type. Key codes can be found under the Keys namespace and represent the keys on a standard full width QWERTY keyboard, custom keyboard layouts do not change the location of the keys. A will always be QWERTY A.
The function returns an integer which you can check to find what the event type for the current key is. There are currently 3 events
KeyReleasedKeyPressedKeyRepeat
These values too are stored under the Keys namespace.
The getAction function returns an InputAction struct given an action name. The InputAction struct looks like this:
struct InputAction
{
FString name{};
uint16_t keyCode{};
uint8_t state{};
};you can use the state member variable to check against the same key events mentioned above. To get all input actions simply call Input::getActions()
InputActions were created so that you can provide a config file to the user to can create custom keybindings. To create keybindings simply open your project's keybindings file under Config/Core/Modules.yaml. It should look like this:
bindings:
- key: empty-binding
val: 1all you need to do is create a new list entry, give it a name and a value like this:
- key: another-binding
val: 65This binding will be for the key A. Key codes can be found under the Framework/Core/Events/Keys.hpp header that defines the Keys namespace.
We don't recommend using this method however and we recommend that you a custom solution to manage keys graphically. Thankfully the Utility class provides 2 functions for converting a key to text. All you need to do it iterate all input actions then use the Utility::keyToText functions to convert your key event to a string. There are 2 variants of this function as can be seen below:
static void keyToText(FString& text, const uint16_t& key, bool bLong) noexcept;static FString keyToText(const uint16_t& key, bool bLong) noexcept;
The difference between the 2 is that the first one uses a reference to a string buffer, while the second just returns a new string. The bLong boolean controls whether to return long or short names. Generally you would like want to use short names for places where you need to save space, like menus, menu bar dropdowns, etc.
This project is supported by all the people who joined our discord server and became beta testers. If you want to join the discord you can click here.
- Home
- Beginner content
- Install guide
- Creating and using the UI components
- The Instance
- The Init Info struct
- Building better titlebar menus
- Textures
- Logging
- Unicode support
- Additional features
- Client-side bar
- Custom type definitions
- Memory management
- C API development
- Config files and Folders
- Interfaces
- Internal Event safety
- Customising the build system
- Modules system
- Collaborating with others
- Advanced content
- Loading dynamic libraries at runtime
- Understanding the library layout
- Compilation mode modifiers
- Supporting plugins
- Production export and deployment
- OS integration tips
- Targeting WASM
- Using a custom rendering engine:
- Using a custom windowing backend:
- Developer and contributor resources
- Misc