每次按下一個鍵時都會調用keyTyped()函數,但方向鍵,Ctrl,Shift,Alt,Backspace和Delete鍵等操作鍵除外。最近輸入的 key 存儲在“ key”變量中。
請注意,按住一個鍵可能會導致多個keyTyped()調用。這是由於操作係統如何處理按鍵並取決於計算機的配置方式。瀏覽器可能將自己的默認行為附加到各種鍵,可以通過在方法末尾添加“return false”來防止這種行為。
用法:
keyTyped()
參數:此方法不接受任何參數。
以下示例說明了p5.js中的keyTyped()函數:
例:
function setup() {
createCanvas(600, 200);
textSize(20);
text("Press any key to display it on the screen", 10, 20);
text("Any of the action keys would not be recognized", 10, 40);
}
function keyTyped() {
clear();
textSize(20);
text("Press any key to display it on the screen", 10, 20);
text("Any of the action keys would not be recognized", 10, 40);
textSize(100);
text(key, 100, 150);
}
輸出:
環境設置: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
參考: https://p5js.org/reference/#/p5/keyTyped
相關用法
- PHP min( )用法及代碼示例
- p5.js box()用法及代碼示例
- p5.js nfp()用法及代碼示例
- p5.js nfs()用法及代碼示例
- PHP pi( )用法及代碼示例
- PHP Ds\Set xor()用法及代碼示例
- p5.js nfc()用法及代碼示例
- PHP max( )用法及代碼示例
- p5.js nf()用法及代碼示例
- d3.js d3.hsl()用法及代碼示例
- p5.js value()用法及代碼示例
注:本文由純淨天空篩選整理自sayantanm19大神的英文原創作品 p5.js | keyTyped() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。