How to control your application using only a keyboard
If you've ever opened the ScrollingTextEntry sample application that ships with Storyboard you will have noticed that it is possible to capture keyboard input. In the context of this sample it is used as a type of notepad.
However, what if you wanted to be able to navigate your application using your keyboard? Let's say for example you have a menu table and you need to cycle through each option using the arrow keys, how would you go about doing that?
To achieve this kind of behavior I recommend utilizing the Focus feature.
Storyboard provides several built in actions that can enable you to manually get and set which control is currently in focus. Actions like gra.screen.focus.direction, gra.screen.focus.set, gra.screen.focus.next, gra.screen.focus.prev.
Additionally, the focus events gre.gotfocus and gre.lostfocus are generated automatically when a control's focus has been updated. You can tie actions to these events to increase complexity.
A sample has been created that demonstrates some of the ways that focus and keyboard inputs can be utilized. You can find the FocusAndKeyboard sample on our public Github in storyboard-samples.
The application consists of two screens: screen 1 demonstrates how controls receive focus when interacted with, and screen 2 demonstrates how using the arrow keys can change which control is in focus. Additionally, pressing enter on this screen will display a message based on which control is currently in focus.
From there you will have the tools necessary to create an application that can be entirely interacted with by keyboard.
Comments
Please sign in to leave a comment.