aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/keybindings/FirmamentKeyboardState.kt
blob: dc20630c6d3dc66b6412605555f88c266e704248 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package moe.nea.firmament.keybindings

import java.util.BitSet
import org.lwjgl.glfw.GLFW
import net.minecraft.client.input.KeyInput

object FirmamentKeyboardState {

	private val pressedScancodes = BitSet()

	@Synchronized
	fun isScancodeDown(scancode: Int): Boolean {
		// TODO: maintain a record of keycodes that were pressed for this scanCode to check if they are still held
		return pressedScancodes.get(scancode)
	}

	@Synchronized
	fun maintainState(keyInput: KeyInput, action: Int) {
		when (action) {
			GLFW.GLFW_PRESS -> pressedScancodes.set(keyInput.scancode)
			GLFW.GLFW_RELEASE -> pressedScancodes.clear(keyInput.scancode)
		}
	}
}