1 decade ago by ShawnSwander
So I was giving my users a command line or chat input functionality by binding all keys to typing to a message box when a chatbind varriable is set to true
Here is a snippet... of the player script
And a basic keybinder function
So feel free to use the concept but my question is can I bind backslash and front slash? --> / \
Here is a snippet... of the player script
if (ig.game.chatbind==true){
if(ig.input.pressed('backspace')&&(ig.game.player.commandline.length > 0)){
ig.game.player.commandline = ig.game.player.commandline.slice(0,- 1)
}
if(ig.input.pressed('enter')&&(ig.game.player.commandline.length <225)){
ig.game.player.commandline = ""
}
if(ig.input.pressed('space')&&(ig.game.player.commandline.length <225)){
ig.game.player.commandline = ig.game.player.commandline + " ";
}
("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+,-.").split("").forEach(function(chr) {
if( ig.input.pressed([chr])&&(ig.game.player.commandline.length<225)){
if (ig.input.state('shift')){
switch(chr){
case '0': chr=")";break;
case '1': chr="!";break;
case '2': chr="@";break;
case '3': chr="#";break;
case '4': chr="$";break;
case '5': chr="%";break;
case '6': chr="^";break;
case '7': chr="&";break;
case '8': chr="*";break;
case '9': chr="(";break;
case '+': chr="=";break;
case ',': chr="<";break;
case '-': chr="_";break;
case '.': chr=">";break;
}
ig.game.player.commandline = ig.game.player.commandline + chr;
}else{
ig.game.player.commandline = ig.game.player.commandline + chr.toLowerCase();
}
}
});
ig.game.player.messagebox = ig.game.player.commandline
}
And a basic keybinder function
keybinder: function(){
console.log("keybinder"+this.chatbind)
ig.input.unbindAll()
switch (this.screenstate){
case 0: //unzoomed standard gameplay
ig.input.bind( ig.KEY.MOUSE1, 'leftclick' );
ig.input.bind( ig.KEY.MOUSE2, 'rightclick' );
ig.input.bind( ig.KEY.NUMPAD_0, '0' );
ig.input.bind( ig.KEY.NUMPAD_1, 'southwest');
ig.input.bind( ig.KEY.NUMPAD_2, 'south');
ig.input.bind( ig.KEY.NUMPAD_3, 'southeast');
ig.input.bind( ig.KEY.NUMPAD_4, 'west');
ig.input.bind( ig.KEY.NUMPAD_5, 'center');
ig.input.bind( ig.KEY.NUMPAD_6, 'east');
ig.input.bind( ig.KEY.NUMPAD_7, 'northwest');
ig.input.bind( ig.KEY.NUMPAD_8, 'north');
ig.input.bind( ig.KEY.NUMPAD_9, 'northeast');
ig.input.bind( ig.KEY.ESC, 'esc');
ig.input.bind( ig.KEY.TAB, 'tab');
ig.input.bind( ig.KEY.ENTER, 'enter');
break;
case 1://zoomed in gameplay
ig.input.bind(ig.KEY.MOUSE2, 'unzoom');
ig.input.bind(ig.KEY.MOUSE1, 'leftclick');
break;
}
if (this.chatbind==true){
ig.input.unbindAll();
ig.input.bind( ig.KEY.MOUSE1, 'leftclick');
ig.input.bind(ig.KEY.SHIFT, 'shift');
("ABCDEFGHIJKLMNOPQRSTUVWXYZ").split("").forEach(function(chr) {
ig.input.bind(ig.KEY[chr],[chr])});
ig.input.bind(ig.KEY.BACKSPACE, 'backspace');
ig.input.bind(ig.KEY.ENTER, 'enter');
ig.input.bind(ig.KEY.SPACE, 'space' );
ig.input.bind( ig.KEY.ESC, 'esc');
ig.input.bind( ig.KEY._0, '0');
ig.input.bind( ig.KEY._1, '1');
ig.input.bind( ig.KEY._2, '2');
ig.input.bind( ig.KEY._3, '3');
ig.input.bind( ig.KEY._4, '4');
ig.input.bind( ig.KEY._5, '5');
ig.input.bind( ig.KEY._6, '6');
ig.input.bind( ig.KEY._7, '7');
ig.input.bind( ig.KEY._8, '8');
ig.input.bind( ig.KEY._9, '9');
ig.input.bind( ig.KEY.PLUS, '+');
ig.input.bind( ig.KEY.COMMA,',');
ig.input.bind( ig.KEY.MINUS,'-');
ig.input.bind( ig.KEY.PERIOD,'.');
}else{
ig.input.bind(ig.KEY.SPACE, 'chatbind' );
}
},
So feel free to use the concept but my question is can I bind backslash and front slash? --> / \
