Skip to content

Commit

Permalink
[Fix] If multiple keyboard layouts were installed, scancode conversio…
Browse files Browse the repository at this point in the history
…n could be based on the wrong layout, causing e.g. B-4 and Note-Off keys to be swapped on a setup with active US keyboard layout but also a German layout being present.

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@22853 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Jan 9, 2025
1 parent 1b50e72 commit 9c80f9c
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions mptrack/CommandSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ constexpr std::pair<CommandID, CommandID> NoteRanges[] =
{kcCommentsStartNotes, kcCommentsStartNoteStops},
};

std::vector<HKL> GetKeyboardLayouts()
{
std::vector<HKL> layouts(GetKeyboardLayoutList(0, nullptr));
GetKeyboardLayoutList(static_cast<int>(layouts.size()), layouts.data());
// GetKeyboardLayoutList appears to return the layouts in no particular order. Always force the active layout to be evaluated first.
layouts.insert(layouts.begin(), GetKeyboardLayout(0));
return layouts;
}

}; // namespace

#ifdef MPT_ALL_LOGGING
Expand Down Expand Up @@ -1685,8 +1694,7 @@ ctx:UID:Description:Modifier:Key:EventMask
"//----------------------------------------------------------------------\n"
"version:" << mpt::ToCharset(mpt::Charset::ASCII, Version::Current().ToUString()) << "\n";

std::vector<HKL> layouts(GetKeyboardLayoutList(0, nullptr));
GetKeyboardLayoutList(static_cast<int>(layouts.size()), layouts.data());
const std::vector<HKL> layouts = GetKeyboardLayouts();

for(int ctx = 0; ctx < kCtxMaxInputContexts; ctx++)
{
Expand Down Expand Up @@ -1743,8 +1751,7 @@ bool CCommandSet::LoadFile(std::istream &iStrm, const mpt::ustring &filenameDesc
CString errText;
int errorCount = 0;

std::vector<HKL> layouts(GetKeyboardLayoutList(0, nullptr));
GetKeyboardLayoutList(static_cast<int>(layouts.size()), layouts.data());
const std::vector<HKL> layouts = GetKeyboardLayouts();

const std::string whitespace(" \n\r\t");
while(iStrm.getline(s, std::size(s)))
Expand Down Expand Up @@ -1911,8 +1918,7 @@ void CCommandSet::ApplyDefaultKeybindings(KeyboardPreset preset, const Version o
QuickChange_SetEffects(*specs);
}

std::vector<HKL> layouts(GetKeyboardLayoutList(0, nullptr));
GetKeyboardLayoutList(static_cast<int>(layouts.size()), layouts.data());
const std::vector<HKL> layouts = GetKeyboardLayouts();

mpt::span<const DefaultKeybinding> defaults;
switch(preset)
Expand Down Expand Up @@ -2172,8 +2178,7 @@ bool CCommandSet::QuickChange_SetEffects(const CModSpecifications &modSpecs)
{
// Hack for situations where a non-latin keyboard layout without A...Z key code mapping may the current layout (e.g. Russian),
// but a latin layout (e.g. EN-US) is installed as well.
std::vector<HKL> layouts(GetKeyboardLayoutList(0, nullptr));
GetKeyboardLayoutList(static_cast<int>(layouts.size()), layouts.data());
const std::vector<HKL> layouts = GetKeyboardLayouts();
SHORT codeNmod = -1;
for(auto i = layouts.begin(); i != layouts.end() && codeNmod == -1; i++)
{
Expand Down

0 comments on commit 9c80f9c

Please sign in to comment.