我应该用哪种语言来编码键盘上的键?

2024-04-20 09:01:32 发布

您现在位置:Python中文网/ 问答频道 /正文

你如何在键盘上编码键?我正在尝试做一个游戏,我想知道我如何才能分配钥匙的作用。例如:

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)
});

此外,这场比赛将是一个模仿的琼脂。你知道吗


Tags: 代码in游戏编码closefeedcellopen
1条回答
网友
1楼 · 发布于 2024-04-20 09:01:32

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;
  }
});

相关问题 更多 >