I have a babylonjs 3D scene where certain keys, when pressed, cause the camera to navigate forwards/backwards, etc. For example pressing T moves the viewer forward.
I am trying to generate an effect where the T key thinks it has been pressed whenever a mousedown occurs anywhere in the window. In short I need mousedown to move the camera forward.
document.addEventListener("mousedown", function(e) {
var code = 116;//T
$('document').trigger(
jQuery.Event('keypress', {
keyCode: code,
which: code
})
);
$("#show").append("mousedown creates: " + code + "<BR>");
});
document.addEventListener("keypress", function(e) {
var key = e.which;
//If it's the T key
if (key == 116) {
$("#show").append("T key has been pressed<BR>");
}
});
// I would like the mousedown event to fire the keypress event
// as if the T key has been pressed
The fiddle is here