|
Post by hikari on Sept 12, 2019 11:59:18 GMT 1
|
|
|
Post by Belouch on Sept 13, 2019 10:11:10 GMT 1
I would love to add that, definitely on the to-do list
|
|
|
Post by hikari on Sept 13, 2019 14:20:38 GMT 1
No other libraries to import, just this code in the page: <script> // Examples: // keyboard.showBuffer(); // keyboard.isKeyPressed(idKey); -> parameter must be an id (number) or the name of the key // if (keyboard.isKeyPressed(32) == true) alert("Spacebar key pressed"); // if (keyboard.isKeyPressed("spacebar") == true) alert("Spacebar key pressed"); function Keyboard(){ this.key = []; this.functionsKeyDown = []; this.functionsKeyUp = []; var totalkeys = 256; for (var i = 0; i < totalkeys; i++) this.key.push(0); this.onkeydown = function(e){ var e = window.event || e; var keyPressedValue = e.keyCode ? e.keyCode : e.charCode; keyboard.key[keyPressedValue] = 1; var functionsAdded = keyboard.functionsKeyDown.length; for (var i = 0; i < functionsAdded; i++) keyboard.functionsKeyDown (); } this.onkeyup = function(e){ var e = window.event || e; var keyPressedValue = e.keyCode ? e.keyCode : e.charCode; keyboard.key[keyPressedValue] = 0;
var functionsAdded = keyboard.functionsKeyUp.length; for (var i = 0; i < functionsAdded; i++) keyboard.functionsKeyUp(); } this.showBuffer = function(){ var buffer = ""; for (var i = 0; i < totalkeys; ++i) if (keyboard.key == 1){ if (buffer == "") buffer = i; else buffer = buffer + ", " + i; }
return buffer; } this.isKeyPressed = function(idKey){ if (typeof(idKey) == "number"){
// Find key by id return keyboard.key[idKey];
} else {
// Find key by name var keyName = idKey; idKey = 0; if (keyName.length == 1 && keyName.toUpperCase()>='A' && keyName.toUpperCase()<='Z') { idKey = keyName.toUpperCase().charCodeAt(0); } else { switch (keyName.toLowerCase()){ case "back": idKey = 8; break; case "tab": idKey = 9; break; case "center": idKey = 12; break; case "enter": idKey = 13; break; case "shift": idKey = 16; break; case "ctrl": idKey = 17; break; case "alt": idKey = 18; break; case "pausa": idKey = 19; break; case "caps": idKey = 20; break; case "esc": idKey = 27; break; case "spacebar": idKey = 32; break; case "right-up": idKey = 33; break; case "right-down": idKey = 34; break; case "left-down": idKey = 35; break; case "left-up": idKey = 36; break; case "left": idKey = 37; break; case "up": idKey = 38; break; case "right": idKey = 39; break; case "down": idKey = 40; break; case "ins": idKey = 45; break; case "canc": idKey = 46; break; case "0": idKey = 48; break; case "1": idKey = 49; break; case "2": idKey = 50; break; case "3": idKey = 51; break; case "4": idKey = 52; break; case "5": idKey = 53; break; case "6": idKey = 54; break; case "7": idKey = 55; break; case "8": idKey = 56; break; case "9": idKey = 57; break; case "<": idKey = 60; break; case "windows": idKey = 91; break; case "0'": idKey = 96; break; case "1'": idKey = 97; break; case "2'": idKey = 98; break; case "3'": idKey = 99; break; case "4'": idKey = 100; break; case "5'": idKey = 101; break; case "6'": idKey = 102; break; case "7'": idKey = 103; break; case "8'": idKey = 104; break; case "9'": idKey = 105; break; case "*": idKey = 106; break; case "+": idKey = 107; break; case "-": idKey = 109; break; case "/": idKey = 111; break; case "f1": idKey = 112; break; case "f2": idKey = 113; break; case "f3": idKey = 114; break; case "f4": idKey = 115; break; case "f5": idKey = 116; break; case "f6": idKey = 117; break; case "f7": idKey = 118; break; case "f8": idKey = 119; break; case "f9": idKey = 120; break; case "f10": idKey = 121; break; case "f11": idKey = 122; break; case "f12": idKey = 123; break; case "blocnum": idKey = 144; break; case "_": idKey = 173; break; case ",": idKey = 188; break; case ".": idKey = 190; break; case "|": idKey = 220; break; default : break; } } return keyboard.key[idKey]; } } } var keyboard = new Keyboard(); document.onkeydown = keyboard.onkeydown; document.onkeyup = keyboard.onkeyup;
keyboard.functionsKeyDown.push(function() {
// W A S D if (keyboard.isKeyPressed("w") == true) location.href = "https://www.agonialands.com/hydre/prophets/main.php?action=move&dir=n"; if (keyboard.isKeyPressed("a") == true) location.href = "https://www.agonialands.com/hydre/prophets/main.php?action=move&dir=w"; if (keyboard.isKeyPressed("s") == true) location.href = "https://www.agonialands.com/hydre/prophets/main.php?action=move&dir=s"; if (keyboard.isKeyPressed("d") == true) location.href = "https://www.agonialands.com/hydre/prophets/main.php?action=move&dir=e";
// with bloc num active if (keyboard.isKeyPressed(104) == true) location.href = "https://www.agonialands.com/hydre/prophets/main.php?action=move&dir=n"; if (keyboard.isKeyPressed(100) == true) location.href = "https://www.agonialands.com/hydre/prophets/main.php?action=move&dir=w"; if (keyboard.isKeyPressed(98) == true) location.href = "https://www.agonialands.com/hydre/prophets/main.php?action=move&dir=s"; if (keyboard.isKeyPressed(102) == true) location.href = "https://www.agonialands.com/hydre/prophets/main.php?action=move&dir=e"; if (keyboard.isKeyPressed(103) == true) location.href = "https://www.agonialands.com/hydre/prophets/main.php?action=move&dir=nw"; if (keyboard.isKeyPressed(105) == true) location.href = "https://www.agonialands.com/hydre/prophets/main.php?action=move&dir=ne"; if (keyboard.isKeyPressed(97) == true) location.href = "https://www.agonialands.com/hydre/prophets/main.php?action=move&dir=sw"; if (keyboard.isKeyPressed(99) == true) location.href = "https://www.agonialands.com/hydre/prophets/main.php?action=move&dir=se";
// with bloc num not active if (keyboard.isKeyPressed(38) == true) location.href = "https://www.agonialands.com/hydre/prophets/main.php?action=move&dir=n"; if (keyboard.isKeyPressed(37) == true) location.href = "https://www.agonialands.com/hydre/prophets/main.php?action=move&dir=w"; if (keyboard.isKeyPressed(40) == true) location.href = "https://www.agonialands.com/hydre/prophets/main.php?action=move&dir=s"; if (keyboard.isKeyPressed(39) == true) location.href = "https://www.agonialands.com/hydre/prophets/main.php?action=move&dir=e"; if (keyboard.isKeyPressed(36) == true) location.href = "https://www.agonialands.com/hydre/prophets/main.php?action=move&dir=nw"; if (keyboard.isKeyPressed(33) == true) location.href = "https://www.agonialands.com/hydre/prophets/main.php?action=move&dir=ne"; if (keyboard.isKeyPressed(35) == true) location.href = "https://www.agonialands.com/hydre/prophets/main.php?action=move&dir=sw"; if (keyboard.isKeyPressed(34) == true) location.href = "https://www.agonialands.com/hydre/prophets/main.php?action=move&dir=se";
});
</script>
PS: the bbcode is breaking the code, i put it temporary in a txt file: wasd.txt
|
|
|
Post by Belouch on Sept 19, 2019 11:45:49 GMT 1
This is now implemented! Thanks a lot to Hikari for this excellent contribution!
|
|