I’m currently working on a workaround for the TextField, and naturally looked up some AS3 topics for an issue regarding Neko crashing anytime you attempted to use any key that was not a letter or number.
I came across this code:
import flash.utils.describeType;
function getKeyboardDict():Dictionary {
var keyDescription:XML = describeType(Keyboard);
var keyNames:XMLList = keyDescription..constant.@name;
var keyboardDict:Dictionary = new Dictionary();
var len:int = keyNames.length();
for(var i:int = 0; i < len; i++) {
keyboardDict[Keyboard[keyNames[i]]] = keyNames[i];
}
return keyboardDict;
}
var keyDict:Dictionary = getKeyboardDict();
trace(keyDict[Keyboard.UP]); //UP
trace(keyDict[Keyboard.SHIFT]); //SHIFT
I got as far as this for converting the code the best I can, but I’m not 100% sure how the OpenFL Dictionary works in Haxe compared to the one in AS3.
EDIT: My latest attempt consists of this code:
public static function getKeyboardDict():Dictionary {
var keyNames = Type.getClassFields(Keyboard);
var keyboardDict:Dictionary = new Dictionary();
var len = keyNames.length;
for(i in 0...len) {
keyboardDict[Reflect.field(Keyboard, keyNames[i])] = keyNames[i];
}
return keyboardDict;
}
But now neko crashes instantly, so Reflect API is probably not a good idea…