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:
parent
b98942dcfd
commit
c8f109eb34
|
@ -51,11 +51,17 @@ namespace BizHawk.Bizware.Input
|
|||
|
||||
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)
|
||||
{
|
||||
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>();
|
||||
while (true)
|
||||
|
@ -63,8 +69,14 @@ namespace BizHawk.Bizware.Input
|
|||
try
|
||||
{
|
||||
var events = _keyboard.GetBufferedKeyboardData();
|
||||
if (events.Length == 0) return eventList;
|
||||
eventList.AddRange(events.Select(e => new KeyEvent(Mapped(e.Key), e.IsPressed)));
|
||||
if (events.Length == 0)
|
||||
{
|
||||
return eventList;
|
||||
}
|
||||
|
||||
eventList.AddRange(events
|
||||
.Select(e => new KeyEvent(Mapped(e.Key), e.IsPressed))
|
||||
.Where(ke => ke.Key != DistinctKey.Unknown));
|
||||
}
|
||||
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;
|
||||
// DInputKey is a scancode as is
|
||||
|
@ -232,7 +244,7 @@ namespace BizHawk.Bizware.Input
|
|||
[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,
|
||||
[0x31] = DInputKey.D1,
|
||||
|
|
|
@ -95,10 +95,13 @@ namespace BizHawk.Bizware.Input
|
|||
lock (rawKeyInput.LockObj)
|
||||
{
|
||||
// TODO: Make a separate enum map for RAWINPUT / VKeys and don't rely on DKeyInput's maps
|
||||
var rawKey = rawKeyInput.HandleAltKbLayouts
|
||||
? DKeyInput.VKeyToDKeyMap.GetValueOrDefault(input->data.keyboard.VKey, RawKey.Unknown)
|
||||
: (RawKey)(input->data.keyboard.MakeCode |
|
||||
(input->data.keyboard.Flags >= RAWKEYBOARD.RIM_KEY.E0 ? 0x80 : 0));
|
||||
var rawKey = (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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue