Skip to content

Commit a0bec17

Browse files
committed
Added support of F13-F24 keys
1 parent d3eae07 commit a0bec17

File tree

6 files changed

+674
-82
lines changed

6 files changed

+674
-82
lines changed

Assets/Tests/InputSystem/CorePerformanceTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,13 @@ public void Performance_ReadEveryKey()
123123

124124
Measure.Method(() =>
125125
{
126+
int keyIndex = 0;
126127
foreach (var key in keyboard.allKeys)
128+
{
129+
if (++keyIndex == (int)KeyEx.IMESelected) // Skip IMESelected as it's not a real key.
130+
continue;
127131
key.ReadValue();
132+
}
128133
})
129134
.MeasurementCount(100)
130135
.WarmupCount(5)

Assets/Tests/InputSystem/CoreTests_Devices.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2674,7 +2674,7 @@ public void Devices_AnyKeyOnKeyboard_DoesNotReactToIMESelected()
26742674
{
26752675
var keyboard = InputSystem.AddDevice<Keyboard>();
26762676

2677-
InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.IMESelected));
2677+
InputSystem.QueueStateEvent(keyboard, new KeyboardState(IMESelected: true));
26782678
InputSystem.Update();
26792679

26802680
Assert.That(keyboard.anyKey.isPressed, Is.False);

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ however, it has to be formatted properly to pass verification tests.
1919
- Pinned Touch Samples sample package dependencies to avoid errors with Cinemachine 3.x and Probuilder 6.x. [ISXB-1245](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1245)
2020
- Fixed an issue where dropdown menu for Path in Input Actions Editor could not be selected from any button position. [ISXB-1309](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1309)
2121

22+
### Added
23+
- Added support of F13-F24 keys. [UUM-44328](https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-44328)
24+
2225
## [1.12.0] - 2025-01-15
2326

2427
### Fixed

Packages/com.unity.inputsystem/InputSystem/Devices/Keyboard.cs

Lines changed: 251 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ public unsafe struct KeyboardState : IInputStateTypeInfo
4646
/// <seealso cref="InputStateBlock.format"/>
4747
public static FourCC Format => new FourCC('K', 'E', 'Y', 'S');
4848

49-
private const int kSizeInBits = Keyboard.KeyCount;
49+
private const int kSizeInBits = Keyboard.KeyCount + 1; // +1 for IMESelected.
5050
internal const int kSizeInBytes = (kSizeInBits + 7) / 8;
5151

52-
[InputControl(name = "anyKey", displayName = "Any Key", layout = "AnyKey", sizeInBits = kSizeInBits - 1, synthetic = true)] // Exclude IMESelected.
52+
[InputControl(name = "anyKey", displayName = "Any Key", layout = "AnyKey", offset = 1, sizeInBits = (int)Key.F24, synthetic = true)]
5353
[InputControl(name = "escape", displayName = "Escape", layout = "Key", usages = new[] {"Back", "Cancel"}, bit = (int)Key.Escape)]
5454
[InputControl(name = "space", displayName = "Space", layout = "Key", bit = (int)Key.Space)]
5555
[InputControl(name = "enter", displayName = "Enter", layout = "Key", usage = "Submit", bit = (int)Key.Enter)]
@@ -163,17 +163,41 @@ public unsafe struct KeyboardState : IInputStateTypeInfo
163163
[InputControl(name = "OEM3", layout = "Key", bit = (int)Key.OEM3)]
164164
[InputControl(name = "OEM4", layout = "Key", bit = (int)Key.OEM4)]
165165
[InputControl(name = "OEM5", layout = "Key", bit = (int)Key.OEM5)]
166-
[InputControl(name = "IMESelected", layout = "Button", bit = (int)Key.IMESelected, synthetic = true)]
166+
[InputControl(name = "f13", displayName = "F13", layout = "Key", bit = (int)Key.F13)]
167+
[InputControl(name = "f14", displayName = "F14", layout = "Key", bit = (int)Key.F14)]
168+
[InputControl(name = "f15", displayName = "F15", layout = "Key", bit = (int)Key.F15)]
169+
[InputControl(name = "f16", displayName = "F16", layout = "Key", bit = (int)Key.F16)]
170+
[InputControl(name = "f17", displayName = "F17", layout = "Key", bit = (int)Key.F17)]
171+
[InputControl(name = "f18", displayName = "F18", layout = "Key", bit = (int)Key.F18)]
172+
[InputControl(name = "f19", displayName = "F19", layout = "Key", bit = (int)Key.F19)]
173+
[InputControl(name = "f20", displayName = "F20", layout = "Key", bit = (int)Key.F20)]
174+
[InputControl(name = "f21", displayName = "F21", layout = "Key", bit = (int)Key.F21)]
175+
[InputControl(name = "f22", displayName = "F22", layout = "Key", bit = (int)Key.F22)]
176+
[InputControl(name = "f23", displayName = "F23", layout = "Key", bit = (int)Key.F23)]
177+
[InputControl(name = "f24", displayName = "F24", layout = "Key", bit = (int)Key.F24)]
178+
[InputControl(name = "IMESelected", layout = "Button", bit = (int)KeyEx.RemappedIMESelected, synthetic = true)] // Use the last bit to hold IME selected state.
167179
public fixed byte keys[kSizeInBytes];
168180

169-
public KeyboardState(params Key[] pressedKeys)
181+
// will be the default in new editor [InputControl(name = "IMESelected", layout = "Button", bit = 0, sizeInBits = 1, synthetic = true)]
182+
//public byte modifiers;
183+
184+
public KeyboardState(params Key[] pressedKeys) : this(false, pressedKeys)
185+
{
186+
}
187+
188+
public KeyboardState(bool IMESelected, params Key[] pressedKeys)
170189
{
171190
if (pressedKeys == null)
172191
throw new ArgumentNullException(nameof(pressedKeys));
173-
174192
fixed(byte* keysPtr = keys)
175193
{
176194
UnsafeUtility.MemClear(keysPtr, kSizeInBytes);
195+
196+
if (IMESelected)
197+
{
198+
MemoryHelpers.WriteSingleBit(keysPtr, (uint)KeyEx.IMESelected, true);
199+
}
200+
177201
for (var i = 0; i < pressedKeys.Length; ++i)
178202
MemoryHelpers.WriteSingleBit(keysPtr, (uint)pressedKeys[i], true);
179203
}
@@ -185,6 +209,14 @@ public void Set(Key key, bool state)
185209
MemoryHelpers.WriteSingleBit(keysPtr, (uint)key, state);
186210
}
187211

212+
internal bool Get(Key key)
213+
{
214+
fixed(byte* keysPtr = keys)
215+
{
216+
return MemoryHelpers.ReadSingleBit(keysPtr, (uint)key);
217+
}
218+
}
219+
188220
public void Press(Key key)
189221
{
190222
Set(key, true);
@@ -858,9 +890,86 @@ public enum Key
858890
/// </summary>
859891
OEM5,
860892

861-
////FIXME: This should never have been a Key but rather just an extra button or state on keyboard
862-
// Not exactly a key, but binary data sent by the Keyboard to say if IME is being used.
863-
IMESelected
893+
/// <summary>
894+
/// Don't use this. This is a dummy key that is only used internally to represent the IME selected state.
895+
/// Will be removed in the future.
896+
/// </summary>
897+
[Obsolete("Don't use this. This is a dummy key that is only used internally to represent the IME selected state. Will be removed in the future.", true)]
898+
IMESelected,
899+
900+
/// <summary>
901+
/// The <see cref="Keyboard.f13Key"/>.
902+
/// </summary>
903+
F13,
904+
905+
/// <summary>
906+
/// The <see cref="Keyboard.f14Key"/>.
907+
/// </summary>
908+
F14,
909+
910+
/// <summary>
911+
/// The <see cref="Keyboard.f15Key"/>.
912+
/// </summary>
913+
F15,
914+
915+
/// <summary>
916+
/// The <see cref="Keyboard.f16Key"/>.
917+
/// </summary>
918+
F16,
919+
920+
/// <summary>
921+
/// The <see cref="Keyboard.f17Key"/>.
922+
/// </summary>
923+
F17,
924+
925+
/// <summary>
926+
/// The <see cref="Keyboard.f18Key"/>.
927+
/// </summary>
928+
F18,
929+
930+
/// <summary>
931+
/// The <see cref="Keyboard.f19Key"/>.
932+
/// </summary>
933+
F19,
934+
935+
/// <summary>
936+
/// The <see cref="Keyboard.f20Key"/>.
937+
/// </summary>
938+
F20,
939+
940+
/// <summary>
941+
/// The <see cref="Keyboard.f21Key"/>.
942+
/// </summary>
943+
F21,
944+
945+
/// <summary>
946+
/// The <see cref="Keyboard.f22Key"/>.
947+
/// </summary>
948+
F22,
949+
950+
/// <summary>
951+
/// The <see cref="Keyboard.f23Key"/>.
952+
/// </summary>
953+
F23,
954+
955+
/// <summary>
956+
/// The <see cref="Keyboard.f24Key"/>.
957+
/// </summary>
958+
F24,
959+
960+
/// <summary>
961+
/// Don't use this. This is a dummy key that is only used internally to represent the IME selected state.
962+
/// Will be removed in the future.
963+
/// FIXME: This should never have been a Key but rather just an extra button or state on keyboard
964+
/// Not exactly a key, but binary data sent by the Keyboard to say if IME is being used.
965+
/// </summary>
966+
//InternalForIMESelected = 127,
967+
}
968+
969+
internal static class KeyEx
970+
{
971+
internal const Key IMESelected = (Key)111; //IMESelected value
972+
internal const Key RemappedIMESelected = (Key)127; //IMESelected value
864973
}
865974

866975
/// <summary>
@@ -919,13 +1028,14 @@ public enum Key
9191028
/// </example>
9201029
/// <seealso cref="InputDevice"/>
9211030
[InputControlLayout(stateType = typeof(KeyboardState), isGenericTypeOfDevice = true)]
922-
public class Keyboard : InputDevice, ITextInputReceiver
1031+
public class Keyboard : InputDevice, ITextInputReceiver, IEventPreProcessor
9231032
{
9241033
/// <summary>
9251034
/// Total number of key controls on a keyboard, i.e. the number of controls
9261035
/// in <see cref="allKeys"/>.
9271036
/// </summary>
928-
public const int KeyCount = (int)Key.OEM5;
1037+
/// <value>Total number of key controls.</value>
1038+
public const int KeyCount = (int)Key.F24 - 1; // without IMESelected
9291039

9301040
/// <summary>
9311041
/// Event that is fired for every single character entered on the keyboard.
@@ -2051,6 +2161,102 @@ public string keyboardLayout
20512161
/// </remarks>
20522162
public KeyControl oem5Key => this[Key.OEM5];
20532163

2164+
/// <summary>
2165+
/// The F13 key on the keyboard
2166+
/// </summary>
2167+
/// <remarks><see cref="KeyControl"/> representing <see cref="Key.F13"/>.
2168+
/// Keyboards may have additional Functions keys that are not part of the standardized 104-key keyboard layout
2169+
/// </remarks>
2170+
public KeyControl f13Key => this[Key.F13];
2171+
2172+
/// <summary>
2173+
/// The F14 key on the keyboard
2174+
/// </summary>
2175+
/// <remarks><see cref="KeyControl"/> representing <see cref="Key.F14"/>.
2176+
/// Keyboards may have additional Functions keys that are not part of the standardized 104-key keyboard layout
2177+
/// </remarks>
2178+
public KeyControl f14Key => this[Key.F14];
2179+
2180+
/// <summary>
2181+
/// The F15 key on the keyboard
2182+
/// </summary>
2183+
/// <remarks><see cref="KeyControl"/> representing <see cref="Key.F15"/>.
2184+
/// Keyboards may have additional Functions keys that are not part of the standardized 104-key keyboard layout
2185+
/// </remarks>
2186+
public KeyControl f15Key => this[Key.F15];
2187+
2188+
/// <summary>
2189+
/// The F16 key on the keyboard
2190+
/// </summary>
2191+
/// <remarks><see cref="KeyControl"/> representing <see cref="Key.F16"/>.
2192+
/// Keyboards may have additional Functions keys that are not part of the standardized 104-key keyboard layout
2193+
/// </remarks>
2194+
public KeyControl f16Key => this[Key.F16];
2195+
2196+
/// <summary>
2197+
/// The F17 key on the keyboard
2198+
/// </summary>
2199+
/// <remarks><see cref="KeyControl"/> representing <see cref="Key.F17"/>.
2200+
/// Keyboards may have additional Functions keys that are not part of the standardized 104-key keyboard layout
2201+
/// </remarks>
2202+
public KeyControl f17Key => this[Key.F17];
2203+
2204+
/// <summary>
2205+
/// The F18 key on the keyboard
2206+
/// </summary>
2207+
/// <remarks><see cref="KeyControl"/> representing <see cref="Key.F18"/>.
2208+
/// Keyboards may have additional Functions keys that are not part of the standardized 104-key keyboard layout
2209+
/// </remarks>
2210+
public KeyControl f18Key => this[Key.F18];
2211+
2212+
/// <summary>
2213+
/// The F19 key on the keyboard
2214+
/// </summary>
2215+
/// <remarks><see cref="KeyControl"/> representing <see cref="Key.F19"/>.
2216+
/// Keyboards may have additional Functions keys that are not part of the standardized 104-key keyboard layout
2217+
/// </remarks>
2218+
public KeyControl f19Key => this[Key.F19];
2219+
2220+
/// <summary>
2221+
/// The F20 key on the keyboard
2222+
/// </summary>
2223+
/// <remarks><see cref="KeyControl"/> representing <see cref="Key.F20"/>.
2224+
/// Keyboards may have additional Functions keys that are not part of the standardized 104-key keyboard layout
2225+
/// </remarks>
2226+
public KeyControl f20Key => this[Key.F20];
2227+
2228+
/// <summary>
2229+
/// The F21 key on the keyboard
2230+
/// </summary>
2231+
/// <remarks><see cref="KeyControl"/> representing <see cref="Key.F21"/>.
2232+
/// Keyboards may have additional Functions keys that are not part of the standardized 104-key keyboard layout
2233+
/// </remarks>
2234+
public KeyControl f21Key => this[Key.F21];
2235+
2236+
/// <summary>
2237+
/// The F22 key on the keyboard
2238+
/// </summary>
2239+
/// <remarks><see cref="KeyControl"/> representing <see cref="Key.F22"/>.
2240+
/// Keyboards may have additional Functions keys that are not part of the standardized 104-key keyboard layout
2241+
/// </remarks>
2242+
public KeyControl f22Key => this[Key.F22];
2243+
2244+
/// <summary>
2245+
/// The F23 key on the keyboard
2246+
/// </summary>
2247+
/// <remarks><see cref="KeyControl"/> representing <see cref="Key.F23"/>.
2248+
/// Keyboards may have additional Functions keys that are not part of the standardized 104-key keyboard layout
2249+
/// </remarks>
2250+
public KeyControl f23Key => this[Key.F23];
2251+
2252+
/// <summary>
2253+
/// The F24 key on the keyboard
2254+
/// </summary>
2255+
/// <remarks><see cref="KeyControl"/> representing <see cref="Key.F24"/>.
2256+
/// Keyboards may have additional Functions keys that are not part of the standardized 104-key keyboard layout
2257+
/// </remarks>
2258+
public KeyControl f24Key => this[Key.F24];
2259+
20542260
/// <summary>
20552261
/// An artificial combination of <see cref="leftShiftKey"/> and <see cref="rightShiftKey"/> into one control.
20562262
/// </summary>
@@ -2299,17 +2505,32 @@ protected override void FinishSetup()
22992505
"oem3",
23002506
"oem4",
23012507
"oem5",
2508+
null, // IMESelected
2509+
"f13",
2510+
"f14",
2511+
"f15",
2512+
"f16",
2513+
"f17",
2514+
"f18",
2515+
"f19",
2516+
"f20",
2517+
"f21",
2518+
"f22",
2519+
"f23",
2520+
"f24",
23022521
};
23032522
m_Keys = new KeyControl[keyStrings.Length];
23042523
for (var i = 0; i < keyStrings.Length; ++i)
23052524
{
2525+
if (string.IsNullOrEmpty(keyStrings[i]))
2526+
continue;
23062527
m_Keys[i] = GetChildControl<KeyControl>(keyStrings[i]);
23072528

23082529
////REVIEW: Ideally, we'd have a way to do this through layouts; this way nested key controls could work, too,
23092530
//// and it just seems somewhat dirty to jam the data into the control here
23102531
m_Keys[i].keyCode = (Key)(i + 1);
23112532
}
2312-
Debug.Assert(keyStrings[(int)Key.OEM5 - 1] == "oem5",
2533+
Debug.Assert(keyStrings[(int)Key.F24 - 1] == "f24",
23132534
"keyString array layout doe not match Key enum layout");
23142535
anyKey = GetChildControl<AnyKeyControl>("anyKey");
23152536
shiftKey = GetChildControl<ButtonControl>("shift");
@@ -2431,6 +2652,25 @@ public void OnIMECompositionChanged(IMECompositionString compositionString)
24312652
}
24322653
}
24332654

2655+
public unsafe bool PreProcessEvent(InputEventPtr currentEventPtr)
2656+
{
2657+
if (currentEventPtr.type == StateEvent.Type)
2658+
{
2659+
var stateEvent = StateEvent.FromUnchecked(currentEventPtr);
2660+
if (stateEvent->stateFormat == KeyboardState.Format)
2661+
{
2662+
var keyboardState = ((KeyboardState*)(stateEvent->stateData));
2663+
if (keyboardState->Get(KeyEx.IMESelected))
2664+
{
2665+
keyboardState->Set(KeyEx.IMESelected, false);
2666+
keyboardState->Set(KeyEx.RemappedIMESelected, true);
2667+
}
2668+
}
2669+
}
2670+
2671+
return true;
2672+
}
2673+
24342674
private InlinedArray<Action<char>> m_TextInputListeners;
24352675
private string m_KeyboardLayoutName;
24362676
private KeyControl[] m_Keys;

0 commit comments

Comments
 (0)