High level keycodes for keys that have multiple positions

Problem: I want to check if the user is pressing shift, or any key that potentially has multiple positions on the keyboard.

Lazy solution: if UIS:IsKeyDown(Enum.KeyCode.LeftShift) then
Modern solution: if UIS:IsKeyDown(Enum.KeyCode.LeftShift) or UIS:IsKeyDown(Enum.KeyCode.RightShift) then
Proposed solution: if UIS:IsKeyDown(Enum.KeyFace.Shift) then

Proposed API Surface

CHANGE UserInputService:IsKeyDown(key: KeyCode)
TO UserInputService:IsKeyDown(key: KeyCode | KeyFace)

DEPRECATE UserInputService:GetStringForKeyCode(key: KeyCode)
ADD UserInputService:GetStringForKey(key: KeyCode | KeyFace)

ADD InputObject.KeyFace KeyFace

CHANGE ContextActionService:UnbindActivate(key: KeyCode)
TO ContextActionService:UnbindActivate(key: KeyCode | KeyFace)

ADD Enum KeyFace (Details below)

Enum.KeyFace has an item for each unique face on the keyboard. It’s just like KeyCode with these changes:

  • Remove LeftShift, RightShift, LeftControl, RightControl, LeftAlt, RightAlt, LeftMeta, RightMeta, LeftSuper, and RightSuper
  • Add Shift, Control, Alt, Meta, and Super. They each refer to both the left and right keys.
  • Remove KeypadZero through KeypadNine. The regular Zero through Nine refers to both number bar and keypad numbers.
  • Remove KeypadEnter, KeypadMinus, KeypadMultiply, KeypadDivide, and KeypadPeriod. The regular Enter, Dash, Asterisk, Slash, and Period refer to both the regular key and the keypad key.

Result: The lazy solution and the correct solution are unified, making it difficult to write improper input handling.

4 Likes

I believe that InputObject.IsModifierKeyDown would satisfy your needs (except for Super).

2 Likes