Advanced Keyboards for Android (multiple USB/BT keyboards support at once!)

grant

Member
CX Code Contributor
3rd Party Module Dev
3rd Party Tool Dev
Joined
Nov 19, 2019
Messages
80
The keyboard support in Cerberus X seems to only support virtual keyboards on Android (it's been a while since I tested it). This module lets you get input from physical keyboards, and you can get input from multiple keyboards separately! You can check if each keyboard was disconnected and even get their names. The module comes with androidkeycodes.cxs that contains some Android keycodes for use with the functions. The key constants built into Cerberus X didn't work with it when I tested it.

I already had the keyboard engine written up, so I just hooked it into Cerberus X. You will need to make a small edit to Cerberus X to install the module though. I don't know how to get around that. Some other improvements could also probably be made.

tick:Void()
This needs to get called at the start of every OnUpdate to pull new info.​
isKeyboardConnected:Bool(device:Int)
Checks if a keyboard is connected.​
keyboardGetDeviceId:Int(device:Int)
This returns the Android input device deviceId and is not used with the other functions of this module.​
getKeyboardCount:Int()
Returns the total number of keyboards. Keyboards that got disconnected after the game started will show up as disconnected, but be replaced when a different keyboard is connected.​
keyboardGetDescription:String(device:Int)
Returns the display name of a keyboard. device is the index from 0 up to getKeyboardCount().​
isKeyPressed:Bool(device:Int, KeyCode:Int)
Returns if the key was just pressed. Set device to -1 to check all keyboards.​
isKeyReleased:Bool(device:Int, KeyCode:Int)
Returns if the key was just released. Set device to -1 to check all keyboards.​
isKeyDown:Bool(device:Int, KeyCode:Int)
Returns if the key is down. Set device to -1 to check all keyboards.​

Demo: The included demo.cxs draws info about all the keyboards on screen.

Install: extract the zip file inside the modules_ext folder inside your Cerberus X installation folder. Rename the resulting folder to advancedkeyboards. Unfortunately you will need to make a small edit to /targets/android-original/modules/native/androidgame.java for it to work and then all your projects will need to import this module when targeting Android. (see included install.txt)

License: zlib/libpng (see included license.txt)

Note: If your game is restarting when a keyboard is connected, change the value of android:configChanges inside AndroidManifest.xml to this (the navigation|keyboard part is what fixes that).
Code:
        android:configChanges="orientation|keyboardHidden|screenSize|navigation|keyboard|screenLayout|smallestScreenSize"

Check out my Advanced Mice module!

If someone wants to do a port to Windows/Mac/Linux, that would be awesome!
 

Attachments

  • AdvancedKeyboards-module-V1.0-for-Cerberus-X-for-Android.zip
    6 KB · Views: 35
Last edited:
Top Bottom