gpt4 book ai didi

java - J2ME 组合按键(一次多个按键)

转载 作者:行者123 更新时间:2023-12-01 05:25:12 24 4
gpt4 key购买 nike

我正在使用这里的keyboard_key变量:

    //overrides the function keyPressed from "lcdui.Canvas"
protected void keyPressed(int keyCode){
keyboard_key = keyCode;
}

检测手机上是否有按键被按下。

但它仅返回最近按下的键,并且不告诉是否可能按下任何其他键。请帮忙!

顺便说一句,我使用 NetBeans 7.0.1 作为 IDE。

最佳答案

...it returns only the key that is pressed most lately and it doesn't tell if any other key might be pressed

您在代码片段中使用它的方式,keyboard_key将始终只包含最近按下的键 - 只是因为它“没有空间”容纳更多的东西。

考虑使用Vector “记住”按下的不同键。

    //define in your class:
Vector keysPressed = new Vector(); // to keep track of keys pressed

//overrides the function keyPressed from "lcdui.Canvas"
protected void keyPressed(int keyCode){
keysPressed.addElement(new Integer(keyCode));
}

旁注给出了这个问题,您可能会从学习 Java 语言基础知识中受益。网上有很多教程 - 只需在网络上搜索“Java 入门”之类的内容即可。

根据您的应用程序要求,考虑覆盖 keyRepeated与 keyPressed 一起。

<小时/>

如果您打算以游戏循环方式处理按键(“一次多个键”表明您可能考虑到这一点),请考虑 lcdui.game.GameCanvas 提供的另一个选项API、方法getKeyStates() :

Gets the states of the physical game keys. Each bit in the returned integer represents a specific key on the device. A key's bit will be 1 if the key is currently down or has been pressed at least once since the last time this method was called. The bit will be 0 if the key is currently up and has not been pressed at all since the last time this method was called. This latching behavior ensures that a rapid key press and release will always be caught by the game loop, regardless of how slowly the loop runs...

关于java - J2ME 组合按键(一次多个按键),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9792076/

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