gpt4 book ai didi

java - 尝试记录按键时长时调用什么函数? (加工)

转载 作者:行者123 更新时间:2023-12-01 22:31:04 27 4
gpt4 key购买 nike

例如,如果我想记录我按下了 b 键并想记录按下该键的时间长度,我该怎么做?

最佳答案

处理起来 super 简单。看看keyPressed()keyReleased() .

// create a variable to store the time
int t = 0;

void setup() {
// whatever you need to do here
}

void draw() {
// do other stuff here
}

// when 'b' key is pressed, store the current
// time in milliseconds since the program started
void keyPressed() {
if (key == 'b') {
t = millis();
}
}

// when the 'b' key is released, subtract the start
// time from the current time to get the duration
void keyReleased() {
if (key == 'b') {
t = millis() - t;
println("b key held for " + t + " milliseconds");
}
}

关于java - 尝试记录按键时长时调用什么函数? (加工),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27751026/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com