https://linen.dev logo
キー操作でOn/Offを切り替える方法
# forum
p
Copy code
javascript
importPackage(Packages.org.lwjgl.input);
︙
if(Keyboard.isKeyDown(Keyboard.KEY_SPACE)){
    なんちゃらら
}
これでなんとかできます
たぶん
a
var isHibeam = dataMap.getBoolean("isHibeam"); if(Keyboard.isKeyDown(Keyboard.KEY_SPACE)){ if(!isHibeam){ dataMap.setBoolean("isHibeam", true, 1); }else{ dataMap.setBoolean("isHibeam", false, 1); } } こんな感じで大丈夫でしょうか...
p
動きそうですがこれってキーが押されている間の毎フレーム実行されるはずだからその対策で1回しか反応しないようにするとかの対策が必要かと
a
了解です ありがとございました
p
このkeyのリストってどっかに載ってますか?
p
KEY_マイクラのキー設定画面に出てる名前
でできると思っています
真実かはわかりません
これか
e
How about
Copy code
js
if (Keyboard.isKeyDown(Keyboard.KEY_SPACE))
{
  dataMap.setBoolean("isHibean", !(dataMap.getBoolean("isHibeam")), 11);
}
? In this case we eliminate one comparison of boolean value. PS. Cause you usually press the key for, like 0.3 or 0.5 or sometimes 1.2 seconds and it means at least 6, 10 or 24 times a render script was ticked thus it means you will see the value rapidly change like a roulette and usually you get the correct result by 50% chance. Personally I suggest you to detect "when last time this script was called what's the status of SPACE" to ensure only one change will be implemented when you continuously press the key.