java keypressed tab_keyPressed()键盘按键函数

2-3.keyPressed()

Name(名称):keyPressed()//键盘按键中断函数

Examples(例子):

// Click on the image to give it focus,单击窗口使其成为焦点

// and then press any key.

然后按任意键

int value = 0;

void draw() {

fill(value);

rect(25, 25, 50, 50);

}

void keyPressed() {

if (value == 0) {

value = 255;

} else {

value = 0;

}

}

Description(描述):The keyPressed() function is called once every time a key is pressed. The key that was pressed is stored in the key variable.

keyPressed()函数每次按下一次时都会被调用一次。按下的键被存储在键变量中。

For non-ASCII keys, use the keyCode variable. The keys included in the ASCII specification (BACKSPACE, TAB, ENTER, RETURN, ESC, and DELETE) do not require checking to see if the key is coded; for those keys, you should simply use the key variable directly (and not keyCode). If you’re making cross-platform projects, note that the ENTER key is commonly used on PCs and Unix, while the RETURN key is used on Macs. Make sure your program will work on all platforms by checking for both ENTER and RETURN.

对于非ASCII键,请使用keyCode变量。 ASCII规范(BACKSPACE,TAB,ENTER,RETURN,ESC和DELETE)中包含的密钥不需要检查密钥是否被编码;对于那些键,你应该直接使用键变量(而不是keyCode)。如果您正在开发跨平台项目,请注意,ENTER键通常用于PC和Unix,而RETURN键则在Mac上使用。通过检查ENTER和RETURN,确保您的程序可以在所有平台上运行。

Because of how operating systems handle key repeats, holding down a key may cause multiple calls to keyPressed(). The rate of repeat is set by the operating system, and may be configured differently on each computer.

由于操作系统如何处理密钥重复,按住一个键可能会导致对keyPressed()的多次调用。重复率由操作系统设置,并且可以在每台计算机上进行不同的配置。

Note that there is a similarly named boolean variable called keyPressed. See its reference page for more information.

请注意,有一个名为keyPressed的类似名称的布尔变量。有关详细信息,请参阅其参考页面。

Mouse and keyboard events only work when a program has draw(). Without draw(), the code is only run once and then stops listening for events.

鼠标和键盘事件只有在程序具有draw()时才可以工作。没有draw(),代码只运行一次,然后停止侦听事件。

Syntax(语法):keyPressed()

keyPressed(event)

Returns(返回值):Void(无)

最后编辑:2017-07-14作者:卡萨布兰卡

eab945d71ea9f94106bb946dfdc7d1e8.png

这个作者貌似有点懒,什么都没有留下。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值