如何在键盘上编码键?我正在尝试制作游戏,我想知道如何为键分配一个角色。例如:
Spacebar = Splits in two
Q = Macro feed
I = Open/Close Inventory
...
我想我可以使用python,但我不确定。我的python代码是:
n = 2
if(UserPress == Spacebar):
CellSplits = True
CellParts = n*2
我认为jQuery可能有效:
$(document).ready(function(){
var $(Cell) = $('.Cell')
$('.Cell').mousefollow(Cell)
});
此外,这场比赛将成为Agario的淘汰赛。
答案 0 :(得分:2)
jQuery中的基本语法是这样的:
$(document).keypress(function(e) {
if(e.which == 32) {
alert('You pressed space');
}
if(e.which == 81) {
alert('You pressed Q');
}
if(e.which == 73) {
alert('You pressed I');
}
});
或者您可以使用switch语句:
$(document).keypress(function(e) {
switch (e.which) {
case 32:
alert('You pressed space');
break;
case 81:
alert('You pressed Q');
break;
case 73:
alert('You pressed I');
break;
}
});