There is a way to “simulate” a key press by calling the broadcastMessage of Key through a “hack” of sorts:
Key["broadcastMessage"]("onKeyUp");
However, I cannot find a way to stuff the code I want to simulate into the Key object. Has anyone run across a “private” variable that I can create a wrapper and populate with the codes I want to simulate?
The reason for this is pretty simple. I want to create a row of fake function keys that the user can press. Instead of linking those for this specific project, I want to be able to re-use the keys in multiple projects and classes that listen to the Key object.
I can pass a code as a parameter by extending the function call above like so:
Key["broadcastMessage"]("onKeyUp", 112); //f1
Key.addListener(this);
private function onKeyUp(keycode:Number) {
if (keycode) {
// use code passed by "fake press"
} else {
// use Key.getCode();
}
}
What I’m trying to do is stuff the Key class with a code of my choosing instead of checking the existence of “keycode”