Making use of GetKey constants to map to functions
So, as part of my current project, I'm trying to handle my input for layered menus and such from the ground up for the sake of experimentation. As such, I have this code currently:
if(AreKeysLeft()) {
({ KEY_UP: startWindow.handleUp,
KEY_DOWN: startWindow.handleDown,
KEY_LEFT: startWindow.handleLeft,
KEY_RIGHT: startWindow.handleRight,
KEY_Z: startWindow.handleAccept,
KEY_X: startWindow.handleCancel
})[GetKey()].call(startWindow);
}
Now, this code does not currently work because the [GetKey()] step returns undefined, which is because KEY_UP, DOWN, etc. are actually numerical constants, and I can't seem to break them down within the object creation to do something like convert KEY_UP to 84, nor can I seem to get the value from GetKey() as its word form. I'm a bit stumped as to what to do here that would still result in legible code while also having equivalent functionality.