fix ctrl/shift (probably more) with alt kb layout handling with RawKeyInput

also fix dinput not filtering out unknown key events (TODO: shouldn't this be handled higher up the input chain? surely we wouldn't want to respond at all to unknown key events)
This commit is contained in:
CasualPokePlayer 2023-10-28 08:21:44 -07:00
parent b98942dcfd
commit c8f109eb34
2 changed files with 25 additions and 10 deletions

View File

@ -51,11 +51,17 @@ namespace BizHawk.Bizware.Input
public static IEnumerable<KeyEvent> Update(Config config) public static IEnumerable<KeyEvent> Update(Config config)
{ {
DistinctKey Mapped(DInputKey k) => KeyEnumMap[config.HandleAlternateKeyboardLayouts ? MapToRealKeyViaScanCode(k) : k]; DistinctKey Mapped(DInputKey k)
=> KeyEnumMap[config.HandleAlternateKeyboardLayouts ? MapToRealKeyViaScanCode(k) : k];
lock (_lockObj) lock (_lockObj)
{ {
if (_keyboard == null || _keyboard.Acquire().Failure || _keyboard.Poll().Failure) return Enumerable.Empty<KeyEvent>(); if (_keyboard == null ||
_keyboard.Acquire().Failure ||
_keyboard.Poll().Failure)
{
return Enumerable.Empty<KeyEvent>();
}
var eventList = new List<KeyEvent>(); var eventList = new List<KeyEvent>();
while (true) while (true)
@ -63,8 +69,14 @@ namespace BizHawk.Bizware.Input
try try
{ {
var events = _keyboard.GetBufferedKeyboardData(); var events = _keyboard.GetBufferedKeyboardData();
if (events.Length == 0) return eventList; if (events.Length == 0)
eventList.AddRange(events.Select(e => new KeyEvent(Mapped(e.Key), e.IsPressed))); {
return eventList;
}
eventList.AddRange(events
.Select(e => new KeyEvent(Mapped(e.Key), e.IsPressed))
.Where(ke => ke.Key != DistinctKey.Unknown));
} }
catch (SharpGen.Runtime.SharpGenException) catch (SharpGen.Runtime.SharpGenException)
{ {
@ -74,7 +86,7 @@ namespace BizHawk.Bizware.Input
} }
} }
private static DInputKey MapToRealKeyViaScanCode(DInputKey key) /*private*/ internal static DInputKey MapToRealKeyViaScanCode(DInputKey key)
{ {
const uint MAPVK_VSC_TO_VK_EX = 0x03; const uint MAPVK_VSC_TO_VK_EX = 0x03;
// DInputKey is a scancode as is // DInputKey is a scancode as is
@ -232,7 +244,7 @@ namespace BizHawk.Bizware.Input
[DInputKey.Unknown] = DistinctKey.Unknown [DInputKey.Unknown] = DistinctKey.Unknown
}; };
/*private*/ internal static readonly IReadOnlyDictionary<uint, DInputKey> VKeyToDKeyMap = new Dictionary<uint, DInputKey> private static readonly IReadOnlyDictionary<uint, DInputKey> VKeyToDKeyMap = new Dictionary<uint, DInputKey>
{ {
[0x30] = DInputKey.D0, [0x30] = DInputKey.D0,
[0x31] = DInputKey.D1, [0x31] = DInputKey.D1,

View File

@ -95,10 +95,13 @@ namespace BizHawk.Bizware.Input
lock (rawKeyInput.LockObj) lock (rawKeyInput.LockObj)
{ {
// TODO: Make a separate enum map for RAWINPUT / VKeys and don't rely on DKeyInput's maps // TODO: Make a separate enum map for RAWINPUT / VKeys and don't rely on DKeyInput's maps
var rawKey = rawKeyInput.HandleAltKbLayouts var rawKey = (RawKey)(input->data.keyboard.MakeCode |
? DKeyInput.VKeyToDKeyMap.GetValueOrDefault(input->data.keyboard.VKey, RawKey.Unknown) (input->data.keyboard.Flags >= RAWKEYBOARD.RIM_KEY.E0 ? 0x80 : 0));
: (RawKey)(input->data.keyboard.MakeCode |
(input->data.keyboard.Flags >= RAWKEYBOARD.RIM_KEY.E0 ? 0x80 : 0)); if (rawKeyInput.HandleAltKbLayouts)
{
rawKey = DKeyInput.MapToRealKeyViaScanCode(rawKey);
}
if (DKeyInput.KeyEnumMap.TryGetValue(rawKey, out var key) && key != DistinctKey.Unknown) if (DKeyInput.KeyEnumMap.TryGetValue(rawKey, out var key) && key != DistinctKey.Unknown)
{ {