Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ object MinecraftKeybindProvider : KeybindGroupProvider {
OneConfigKeybind::class.java,
)
prop.addMetadata("visualizer", Visualizer.KeybindVisualizer::class.java)
prop.addMetadata("singleKey", true)
prop.addMetadata("default", mapping.defaultKey.toOneConfigKeybind())
prop.addMetadata("category", categoryLabel(mapping))
prop.addMetadata("subcategory", "Minecraft Controls")
return prop
Expand Down Expand Up @@ -155,13 +157,17 @@ object MinecraftKeybindProvider : KeybindGroupProvider {

private fun KeyMapping.toOneConfigKeybind(): OneConfigKeybind {
val key = runCatching { InputConstants.getKey(saveString()) }.getOrDefault(InputConstants.UNKNOWN)
return when (key.type) {
return key.toOneConfigKeybind()
}

private fun InputConstants.Key.toOneConfigKeybind(): OneConfigKeybind {
return when (type) {
InputConstants.Type.KEYSYM -> {
if (key.value > 0) OneConfigKeybind(intArrayOf(key.value), null, KeyModifiers.NONE, 0L) { true }
if (value > 0) OneConfigKeybind(intArrayOf(value), null, KeyModifiers.NONE, 0L) { true }
else OneConfigKeybind(null, null, KeyModifiers.NONE, 0L) { true }
}
InputConstants.Type.MOUSE -> {
if (key.value >= 0) OneConfigKeybind(null, intArrayOf(key.value), KeyModifiers.NONE, 0L) { true }
if (value >= 0) OneConfigKeybind(null, intArrayOf(value), KeyModifiers.NONE, 0L) { true }
else OneConfigKeybind(null, null, KeyModifiers.NONE, 0L) { true }
}
else -> OneConfigKeybind(null, null, KeyModifiers.NONE, 0L) { true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ private fun KeyEvent.awtKeyEventId(): Int? = runCatching {
@Composable
fun KeybindOption(data: KeybindOptionData) {
val theme = LocalTheme.current
val singleKey = data.prop.getMetadata<Boolean>("singleKey") == true
val interactionSource = rememberInteractionSource()
val isHovered by interactionSource.collectIsHoveredAsState()
var recording by remember(data.prop) { mutableStateOf(false) }
Expand Down Expand Up @@ -213,6 +214,11 @@ fun KeybindOption(data: KeybindOptionData) {
// would match nothing useful (or, for code 0, match everything).
val glfwCode = event.utf16CodePoint
if (glfwCode <= 0) return@onKeyEvent true
if (singleKey) {
applyKeybind(intArrayOf(glfwCode), null)
recording = false
return@onKeyEvent true
}
if (glfwCode !in recordedKeys) recordedKeys.add(glfwCode)
heldKeys.add(glfwCode)
return@onKeyEvent true
Expand Down
Loading