-
Notifications
You must be signed in to change notification settings - Fork 19
UScreen: improved input handling (via optional interface) #125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
a3c342d
6e0b76a
139666a
951e5a6
d8b45ce
838a66b
c20a4ba
1cc2422
73e8e28
7b3d183
1b0bfa6
705f710
b235141
2097acf
db1fdc3
eafc88b
716576d
970674e
b89c0f6
cea00b8
b3ab8f0
56ea5e7
c0cdcb0
accfa3c
77134dc
f2d52e3
74df627
c70ade6
a0b8831
82b82a1
7fd377c
c0e344c
5da550e
b0a244f
36f0f98
200b317
8e699a3
8404585
c8a438c
07ef250
d1a5cd4
53fb6c7
250088c
16bab97
43a7905
3fd5319
5402cf7
0c4c400
27212ed
d9a1f6b
6669e89
dd0bf25
0fa2810
e3f9a1f
077b0f5
ba5403e
a9da605
0e948fd
522acc4
f3f15af
0a05061
c0a5cc5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -270,40 +270,69 @@ object UKeyboard { | |
| //#endif | ||
| } | ||
|
|
||
| @Deprecated("Use isOSModifierKeyDown() instead if you want the platform-appropriate modifier key (Ctrl on Windows/Linux, Command on Mac). " + | ||
| "Alternatively use isControlKeyDown() or isCommandKeyDown() if you specifically want to check for Ctrl or Command respectively.") | ||
| @JvmStatic | ||
| fun isCtrlKeyDown(): Boolean = if (UMinecraft.isRunningOnMac) { | ||
| isKeyDown(KEY_LMETA) || isKeyDown(KEY_RMETA) | ||
| } else isKeyDown(KEY_LCONTROL) || isKeyDown(KEY_RCONTROL) | ||
|
|
||
| @Deprecated("If using from a key event, use the provided modifiers instead of calling this method.") | ||
| @JvmStatic | ||
| fun isOSModifierKeyDown(): Boolean = | ||
| if (UMinecraft.isRunningOnMac) isCommandKeyDown() | ||
| else isControlKeyDown() | ||
|
|
||
| @Deprecated("If using from a key event, use the provided modifiers instead of calling this method.") | ||
| @JvmStatic | ||
| fun isCommandKeyDown(): Boolean = isKeyDown(KEY_LMETA) || isKeyDown(KEY_RMETA) | ||
|
|
||
| @Deprecated("If using from a key event, use the provided modifiers instead of calling this method.") | ||
| @JvmStatic | ||
| fun isControlKeyDown(): Boolean = isKeyDown(KEY_LCONTROL) || isKeyDown(KEY_RCONTROL) | ||
|
|
||
| @Deprecated("If using from a key event, use the provided modifiers instead of calling this method.") | ||
| @JvmStatic | ||
| fun isShiftKeyDown(): Boolean = isKeyDown(KEY_LSHIFT) || isKeyDown(KEY_RSHIFT) | ||
|
|
||
| @Deprecated("If using from a key event, use the provided modifiers instead of calling this method.") | ||
| @JvmStatic | ||
| fun isAltKeyDown(): Boolean = isKeyDown(KEY_LMENU) || isKeyDown(KEY_RMENU) | ||
|
|
||
| @Deprecated("Inconsistent ctrl modifier behaviour depending on OS and MC versions", replaceWith = ReplaceWith("getKeyModifiers()")) | ||
| @JvmStatic | ||
| fun getModifiers(): Modifiers = Modifiers(isCtrlKeyDown(), isShiftKeyDown(), isAltKeyDown()) | ||
| fun getModifiers(): Modifiers = Modifiers(isCtrlKeyDown(), isShiftKeyDown(), isAltKeyDown(), isCommandKeyDown()) | ||
|
|
||
| @JvmStatic | ||
| fun isKeyComboCtrlA(key: Int): Boolean = key == KEY_A && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown() | ||
| fun getKeyModifiers(): Modifiers = Modifiers(isControlKeyDown(), isShiftKeyDown(), isAltKeyDown(), isCommandKeyDown()) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought: Not sure we should even provide this new variant of the You usually shouldn't be using |
||
|
|
||
| @Deprecated("If using from a key event, use the provided modifiers instead of calling this method.") | ||
| @JvmStatic | ||
| fun isKeyComboCtrlC(key: Int): Boolean = key == KEY_C && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown() | ||
| fun isKeyComboCtrlA(key: Int): Boolean = key == KEY_A && isOSModifierKeyDown() && !isShiftKeyDown() && !isAltKeyDown() | ||
|
|
||
| @Deprecated("If using from a key event, use the provided modifiers instead of calling this method.") | ||
| @JvmStatic | ||
| fun isKeyComboCtrlV(key: Int): Boolean = key == KEY_V && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown() | ||
| fun isKeyComboCtrlC(key: Int): Boolean = key == KEY_C && isOSModifierKeyDown() && !isShiftKeyDown() && !isAltKeyDown() | ||
|
|
||
| @Deprecated("If using from a key event, use the provided modifiers instead of calling this method.") | ||
| @JvmStatic | ||
| fun isKeyComboCtrlX(key: Int): Boolean = key == KEY_X && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown() | ||
| fun isKeyComboCtrlV(key: Int): Boolean = key == KEY_V && isOSModifierKeyDown() && !isShiftKeyDown() && !isAltKeyDown() | ||
|
|
||
| @Deprecated("If using from a key event, use the provided modifiers instead of calling this method.") | ||
| @JvmStatic | ||
| fun isKeyComboCtrlY(key: Int): Boolean = key == KEY_Y && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown() | ||
| fun isKeyComboCtrlX(key: Int): Boolean = key == KEY_X && isOSModifierKeyDown() && !isShiftKeyDown() && !isAltKeyDown() | ||
|
|
||
| @Deprecated("If using from a key event, use the provided modifiers instead of calling this method.") | ||
| @JvmStatic | ||
| fun isKeyComboCtrlZ(key: Int): Boolean = key == KEY_Z && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown() | ||
| fun isKeyComboCtrlY(key: Int): Boolean = key == KEY_Y && isOSModifierKeyDown() && !isShiftKeyDown() && !isAltKeyDown() | ||
|
|
||
| @Deprecated("If using from a key event, use the provided modifiers instead of calling this method.") | ||
| @JvmStatic | ||
| fun isKeyComboCtrlShiftZ(key: Int): Boolean = key == KEY_Z && isCtrlKeyDown() && isShiftKeyDown() && !isAltKeyDown() | ||
| fun isKeyComboCtrlZ(key: Int): Boolean = key == KEY_Z && isOSModifierKeyDown() && !isShiftKeyDown() && !isAltKeyDown() | ||
|
|
||
| @Deprecated("If using from a key event, use the provided modifiers instead of calling this method.") | ||
| @JvmStatic | ||
| fun isKeyComboCtrlShiftZ(key: Int): Boolean = key == KEY_Z && isOSModifierKeyDown() && isShiftKeyDown() && !isAltKeyDown() | ||
|
|
||
| //#if STANDALONE | ||
| //$$ internal val keysDown = mutableSetOf<Int>() | ||
|
|
@@ -390,19 +419,40 @@ object UKeyboard { | |
| @JvmStatic | ||
| fun getKeyName(keyCode: Int): String? = getKeyName(keyCode, -1) | ||
|
|
||
| data class Modifiers(val isCtrl: Boolean, val isShift: Boolean, val isAlt: Boolean) | ||
| data class Modifiers( | ||
| val isCtrl: Boolean, | ||
| val isShift: Boolean, | ||
| val isAlt: Boolean, | ||
| val isSuper: Boolean, | ||
| ) { | ||
|
Comment on lines
-393
to
+427
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: Breaking change. Also need to supply a three-args |
||
| @Deprecated("Old constructor") | ||
| constructor(isCtrl: Boolean, isShift: Boolean, isAlt: Boolean) : | ||
| this(isCtrl, isShift, isAlt, isSuper = isCommandKeyDown()) | ||
|
|
||
| /** | ||
| * Checks that only the OS specific modifier key is active (Ctrl on Windows/Linux, Command (super) on Mac). | ||
| */ | ||
| fun isPlatformModifierActive() = if (UMinecraft.isRunningOnMac) isSuper else isCtrl | ||
|
|
||
| fun isOnlyPlatformModifierActive() = | ||
| if (UMinecraft.isRunningOnMac) isSuper && !isShift && !isAlt && !isCtrl | ||
| else isCtrl && !isShift && !isAlt && !isSuper | ||
|
|
||
| } | ||
|
|
||
| //#if MC>=11502 | ||
| //$$ internal fun Modifiers?.toInt() = listOf( | ||
| //$$ this?.isCtrl to GLFW.GLFW_MOD_CONTROL, | ||
| //$$ this?.isShift to GLFW.GLFW_MOD_SHIFT, | ||
| //$$ this?.isAlt to GLFW.GLFW_MOD_ALT, | ||
| //$$ this?.isSuper to GLFW.GLFW_MOD_SUPER, | ||
| //$$ ).sumOf { (modifier, value) -> if (modifier == true) value else 0 } | ||
| //$$ | ||
| //$$ internal fun Int.toModifiers() = Modifiers( | ||
| //$$ isCtrl = (this and GLFW.GLFW_MOD_CONTROL) != 0, | ||
| //$$ isShift = (this and GLFW.GLFW_MOD_SHIFT) != 0, | ||
| //$$ isAlt = (this and GLFW.GLFW_MOD_ALT) != 0, | ||
| //$$ isSuper = (this and GLFW.GLFW_MOD_SUPER) != 0, | ||
| //$$ ) | ||
| //#endif | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Would call this
isSuperKeyDown, for consistency with ourModifier.isSuper.That, or
isMetaKeyDown, since that's what we call ourKEY_constants. But I think staying consistent with the new stuff (and lwjgl3, which also calls themGLFW_KEY_LEFT/RIGHT_SUPER) is better here.I don't think we're calling it
Commandanywhere else.