Skip to content

Commit

Permalink
fix(KeyPressedPreferNative): disallow key input when the window is no…
Browse files Browse the repository at this point in the history
…t focused
  • Loading branch information
phu54321 committed Oct 21, 2024
1 parent 8fc25ce commit 0bef0f0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/bms/player/beatoraja/input/KeyBoardInputProcesseor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.utils.IntArray;
import com.badlogic.gdx.Input.Keys;
import org.lwjgl.opengl.Display;

/**
* キーボード入力処理用クラス
Expand Down Expand Up @@ -98,11 +99,18 @@ public void clear() {

public void poll(final long microtime) {
if (!textmode) {
final boolean isWindowFocused = Display.isActive();

for (int i = 0; i < keys.length; i++) {
if(keys[i] < 0) {
continue;
}
final boolean pressed = KeyPressedPreferNative.isKeyPressed(keys[i]);

// KeyPressedPreferNative.isKeyPressed internally uses GetAsyncKeyState when
// used on windows, so it returns true even if the window is NOT foreground.
// We use `isWindowFocused` so that the key will only be pressed when the game
// is the focused application.
final boolean pressed = isWindowFocused && KeyPressedPreferNative.isKeyPressed(keys[i]);
if (pressed != keystate[keys[i]] && microtime >= keytime[keys[i]] + duration * 1000) {
keystate[keys[i]] = pressed;
keytime[keys[i]] = microtime;
Expand Down

0 comments on commit 0bef0f0

Please sign in to comment.