Code Examples - accessible-virtual-keyboard/backend GitHub Wiki
The following is a an examples of the minimal code needed to create a working keyboard using the provided interface implementations in the backend.
Minimal example without GUI
Keyboard keyboard = new CoreKeyboard();
keyboard.addOutputDevice(new ConsoleOutput());
Layout layout = new SimpleExampleLayout(keyboard);
InputInterface input = layout;
// You must implement your own source of input
// The following is just hardcoded
input.sendInputSignal(InputType.INPUT2); // Move to letter "a"
input.sendInputSignal(InputType.INPUT1); // Select letter "a"
input.sendInputSignal(InputType.INPUT1); // Select send button.
// An "a" should now have been printed to the console
Minimal example with GUI
Shows how to notify the GUI when the layout changes
Keyboard keyboard = new CoreKeyboard();
keyboard.addOutputDevice(new ConsoleOutput());
Layout layout = new SimpleExampleLayout(keyboard);
InputInterface input = layout;
// Should draw a graphical view of the layout
final SomeKindOfGUIImplementation gui = new SomeKindOfGUIImplementation(layout);
layout.addLayoutListener(new Layout.LayoutListener() {
@Override
public void onLayoutChanged() {
gui.update(); // Update the graphical view
}
});
// You must implement your own source of input
// The following is just hardcoded
input.sendInputSignal(InputType.INPUT2); // Move to letter "a"
input.sendInputSignal(InputType.INPUT1); // Select letter "a"
input.sendInputSignal(InputType.INPUT1); // Select send button.
// An "a" should now have been printed to the console
Example using the binary search layout with suggestions. (Without GUI)
final Keyboard keyboard = new CoreKeyboard();
keyboard.addOutputDevice(new ConsoleOutput());
final Dictionary dictionary = new DictionaryHandler(ResourceHandler.loadDictionaryFromFile("filename-of-dictionary.txt"));
BinarySearchLayout layout = new BinarySearchLayout(keyboard);
keyboard.addStateListener(new Keyboard.KeyboardListener() {
@Override
public void onOutputBufferChange(String oldBuffer, String newBuffer) {
layout.setSuggestions(dictionary.getSuggestionsStartingWith(keyboard.getCurrentWord()));
}
});
InputInterface input = layout;
// You must implement your own source of input
input.sendInputSignal(InputType.INPUT1); // Select left letter group
input.sendInputSignal(InputType.INPUT2); // Select right letter group
input.sendInputSignal(InputType.INPUT1); // Select left letter group etc...