Building a game using Blueprints but also learning C++ at the same time. Can anybody tell me how to expose AreCapsLocked to Blueprint? It really important for my game to be able to know the current state of the Caps Lock, especially since it could be turned on before the player starts the game.
In order to get the current state of the Caps Lock, the AreCapsLocked() method has to be called through the current application instance. Although this instance is platform specific, Unreal Engine gives you the necessary API to check the Caps Lock state in a generic and cross-platform way. However, you would have to do a little bit of work to properly expose this method to Blueprints. Here’s a step by step guide on how to make this a static BlueprintPure node that can be accessed from any blueprint:
To access the running application instance, you have to first enable Slate and SlateCore modules. Open your Code Editor, go to [YourProjectName].Build.cs and either uncomment or add this line at the end of the class
We’re going to create a new static method within Blueprint Function Library class. You can skip to step#3 If you have already added one to your project. To create a Blueprint Function Library, go to the Editor, click on Add New > New C++ class > Scroll all the way down and select Blueprint Function Library as its parent. Let’s name it MyBlueprintFunctionLibrary (a better naming convention can be something like [YourProjectName]BlueprintFunctionLibrary).
In the header file, create a new static method named AreCapsLocked (or anything that makes sense) and mark it with UFUNCTION specifier BlueprintPure:
There you go! Compile your code, go to any blueprint and type “CapsLock”. You should now be able to see and get this node.