📜  p5.js | keyReleased()函数

📅  最后修改于: 2022-05-13 01:56:39.379000             🧑  作者: Mango

p5.js | keyReleased()函数

keyReleased()函数会在每次按下某个键时调用一个键。最近键入的 ASCII 密钥存储在 'key' 变量中,但是,它不区分大小写字符。可以在“keyCode”变量中使用它们各自的代码访问非 ASCII字符。

不同的浏览器可能会将自己的默认行为附加到某些键上。这可以通过在函数末尾添加“return false”来防止。

句法:

keyReleased()

参数:此方法不接受任何参数。

以下示例说明了 p5.js 中的keyReleased()函数

例子:

function setup() {
  createCanvas(600, 200);
  textSize(20);
  text("Press any key to check if "
        + "it is being pressed or "
        + "released", 10, 20);
}
   
function keyPressed() {
  clear();
  textSize(20);
  text("Press any key to check if "
        + "it is being pressed or "
        + "released", 10, 20);
  textSize(30);
    
  text("You are pressing: " 
        + key, 20, 100);
}
   
function keyReleased() {
  clear();
  textSize(20);
  text("Press any key to check if "
        + "it is being pressed or "
        + "released", 10, 20);
  textSize(30);
    
  text("You released: "
        + key, 20, 100);
}

输出:
显示按下释放

环境设置: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/

参考: https://p5js.org/reference/#/p5/keyReleased