script to add a button to simulate tab key for mobile users

So there was a request earlier today on newbie for the ability to simulate pressing the tab button for targeting while on a mobile device. If you add a new button in the buttons section add the following to the script section of the button you will have your non-tab tab button that is clickable in the nexus UI

******************************** SCRIPT BEGINS BELOW
function simulateKey (keyCode, type, modifiers) {
var evtName = (typeof(type) === "string") ? "key" + type : "keydown";
var modifier = (typeof(modifiers) === "object") ? modifier : {};

var event = document.createEvent("HTMLEvents");
event.initEvent(evtName, true, false);
event.keyCode = keyCode;
for (var i in modifiers) {
event[i] = modifiers[i];
}

document.dispatchEvent(event);
}

// Setup some tests

var onKeyEvent = function (event) {
var state = "pressed";
if (event.type !== "keypress") {
state = event.type.replace("key", "");
}
console.log("Key with keyCode " + event.keyCode + " is " + state);
};

document.addEventListener("keypress", onKeyEvent, false);
document.addEventListener("keydown", onKeyEvent, false);
document.addEventListener("keyup", onKeyEvent, false);

// Using the function
simulateKey(9);
simulateKey(9, "up");
simulateKey(9, "press");

Comments

Sign In or Register to comment.