Forráskód Böngészése

Typing keyboard goes by the key's place, not its letter, as FL (QWERTZ, AZERTY, Dvorak; round 190bm)

On a German keyboard Z and Y were swapped on the typing keyboard: LYNX matched JUCE's key code, which is the
character the key types. FL's key table is indexed by scan code (FUN_01182670 / FUN_011828c0, REA round 169f).

- core/KeyMap: the typing block by PC scan code (usKeyOfScanCode) and physicalKey(), which takes the OS's
  'scan code of the key that types this character' as a callback
- ui/WindowOwner scanCodeOfKeyCode(): Windows VkKeyScanExW + MapVirtualKeyExW on the active layout; Linux the
  active XKB group's keysyms on an Xlib connection of its own; macOS UCKeyTranslate over the ANSI virtual keys
  (looked up at run time; not compiled here)
- MainComponent::typingKey asks by place; shortcuts and the held-key polling stay by character
- tests: simulated QWERTZ / AZERTY / Dvorak tables play every FL layout as the US keyboard does
Ka1-S 3 hete
szülő
commit
bf44bf1e5c

+ 29 - 0
src/core/KeyMap.cpp

@@ -710,6 +710,35 @@ std::vector<int> typingPianoNotes (int key, int octave, int root, int layout)
     return typingPianoKey (key, octave, root, layout).notes;
 }
 
+namespace
+{
+// layoutKeys by PC scan code (set 1): 0x02..0x0D the number row, 0x10..0x1B the Q row, 0x1E..0x28 the A row, 0x29 `,
+// 0x2B \, 0x2C..0x35 the Z row (the gaps are Backspace / Tab, Enter / Ctrl and the left Shift)
+constexpr int firstTypingScanCode = 0x02, lastTypingScanCode = 0x35;
+constexpr char usKeyByScanCode[] = "1234567890-=\0\0QWERTYUIOP[]\0\0ASDFGHJKL;'`\0\\ZXCVBNM,./";
+static_assert (sizeof (usKeyByScanCode) - 1 == lastTypingScanCode - firstTypingScanCode + 1);
+} // namespace
+
+int typingpiano::usKeyOfScanCode (int scanCode) noexcept
+{
+    return scanCode >= firstTypingScanCode && scanCode <= lastTypingScanCode ? (int) (unsigned char) usKeyByScanCode[scanCode - firstTypingScanCode] : 0;
+}
+
+int typingpiano::scanCodeOfUsKey (int key) noexcept
+{
+    const auto c = key >= 'a' && key <= 'z' ? key - 'a' + 'A' : key;
+    for (int scan = firstTypingScanCode; scan <= lastTypingScanCode; ++scan)
+        if (c > 0 && usKeyOfScanCode (scan) == c)
+            return scan;
+    return 0;
+}
+
+int typingpiano::physicalKey (int keyCode, const ScanCodeLookup& scanCodeOf)
+{
+    const auto scanCode = scanCodeOf != nullptr ? scanCodeOf (keyCode) : 0;
+    return scanCode > 0 ? usKeyOfScanCode (scanCode) : keyCode;
+}
+
 KeyMap::KeyMap()
 {
     resetToDefaults();

+ 20 - 0
src/core/KeyMap.h

@@ -10,6 +10,7 @@
 // always work.
 
 #include <cstdint>
+#include <functional>
 #include <optional>
 #include <string>
 #include <vector>
@@ -109,6 +110,25 @@ struct TypingKey
 TypingKey typingPianoKey (int key, int octave, int root, int layout);
 std::vector<int> typingPianoNotes (int key, int octave, int root, int layout); // typingPianoKey().notes
 
+// The typing keyboard goes by the key's PLACE, not its letter, as FL's does (FL's key table is indexed by the scan
+// codes 2..0x35, FUN_01182670 / FUN_011828c0, round 169f): on a German keyboard (QWERTZ) the key left of X plays the
+// Z row's first note although it types Y; on AZERTY the Q row starts at the key that types A, and the number row plays
+// without Shift. Shortcuts (Ctrl+Z...) stay by character.
+namespace typingpiano
+{
+    // The key a US keyboard has at PC scan code `scanCode` (set 1: 0x02 = '1' ... 0x10 = 'Q' ... 0x2C = 'Z' ... 0x35 =
+    // '/'; the same numbers as Linux's evdev key codes), upper case; 0 for a key outside the typing block (the ISO
+    // key next to the left Shift, 0x56, has no US place).
+    int usKeyOfScanCode (int scanCode) noexcept;
+    int scanCodeOfUsKey (int key) noexcept; // the reverse; 0 for none
+    // The scan code of the key that gives `keyCode` (the UI's key code: the key's unshifted character in the user's
+    // keyboard layout); 0 = not known (no such key in the layout, or the platform can't tell).
+    using ScanCodeLookup = std::function<int (int keyCode)>;
+    // The US key at the place of the key that gives `keyCode`: what typingPianoKey() is asked for. A key whose place
+    // is not known stays as it is (by character, as before); a key at a place outside the typing block gives 0.
+    int physicalKey (int keyCode, const ScanCodeLookup& scanCodeOf);
+}
+
 // The upper-case printable character of a key code (JUCE's getKeyCode()), or 0 for any other key. On Windows JUCE's
 // F-keys, numpad keys and arrows are VK | 0x10000: a plain towupper() of them (16-bit) gave F4 -> 'S', F1 -> 'P',
 // Numpad1 -> 'A', so the editors took them for tool letters (issue #12, found by round 165q).

+ 10 - 6
src/ui/MainComponent.cpp

@@ -1675,7 +1675,7 @@ bool MainComponent::keyPressed (const juce::KeyPress& key)
     const auto chord = chordFromKeyPress (key);
 
     // 1. the typing piano: the keys its layout takes (notes, FL's LOCK) win over the shortcuts; FL's FREE keys don't
-    const auto typed = typingKey (chord);
+    const auto typed = typingKey (key);
     if (typed.taken)
     {
         const auto code = key.getKeyCode();
@@ -1725,9 +1725,13 @@ bool MainComponent::isPlainKey (const keys::Chord& chord) noexcept
     return (chord.mods & (keys::ctrl | keys::alt | keys::shift)) == 0;
 }
 
-keys::TypingKey MainComponent::typingKey (const keys::Chord& chord) const
+keys::TypingKey MainComponent::typingKey (const juce::KeyPress& key) const
 {
-    return typingPiano && isPlainKey (chord) ? keys::typingPianoKey (chord.key, typingOctave, typingRoot, typingLayout) : keys::TypingKey {};
+    if (! typingPiano || ! isPlainKey (chordFromKeyPress (key)))
+        return {};
+    // the key's place (FL's table goes by scan code): a German keyboard's Y, left of X, is the Z row's first key
+    const auto place = keys::typingpiano::physicalKey (key.getKeyCode(), [] (int code) { return scanCodeOfKeyCode (code); });
+    return keys::typingPianoKey (keys::letterOfKeyCode (place), typingOctave, typingRoot, typingLayout);
 }
 
 void MainComponent::releaseTypingLaunches (bool all)
@@ -1750,9 +1754,9 @@ bool MainComponent::keyFromSecondaryWindow (const juce::KeyPress& key)
     const auto typingIntoText = dynamic_cast<juce::TextEditor*> (juce::Component::getCurrentlyFocusedComponent()) != nullptr;
     const auto chord = chordFromKeyPress (key);
     // issue #117: the typing piano plays from Sytrus's window (any LYNX window) too; its release is polled (timer)
-    if (keys::KeyMap::secondaryWindowPlaysNote (typingKey (chord).taken, typingIntoText))
+    if (keys::KeyMap::secondaryWindowPlaysNote (typingKey (key).taken, typingIntoText))
         return keyPressed (key);
-    const auto action = keyMap.findFromSecondaryWindow (chord, typingIntoText, typingPiano && (! isPlainKey (chord) || typingKey (chord).taken));
+    const auto action = keyMap.findFromSecondaryWindow (chord, typingIntoText, typingPiano && (! isPlainKey (chord) || typingKey (key).taken));
     return ! action.empty() && runAction (action);
 }
 
@@ -1760,7 +1764,7 @@ bool MainComponent::keyFromPluginView (const juce::KeyPress& key, bool optionOn)
 {
     // the typing piano as over the main window (its release is polled, MainComponent::keyStateChanged). With the
     // plugin's "Typing keyboard priority" off (LYNX first) the shortcuts run too; keys that do nothing here stay the plugin's.
-    if (typingKey (chordFromKeyPress (key)).taken)
+    if (typingKey (key).taken)
         return keyPressed (key);
     return optionOn && keyFromSecondaryWindow (key);
 }

+ 3 - 1
src/ui/MainComponent.h

@@ -226,7 +226,9 @@ private:
     perf::MidiMapping typingPerformance;
     std::map<int, std::vector<int>> typingLaunches;
     static bool isPlainKey (const keys::Chord& chord) noexcept; // no Ctrl / Alt / Shift
-    keys::TypingKey typingKey (const keys::Chord& chord) const; // what the typing keyboard does with it (nothing when off)
+    // what the typing keyboard does with a key (nothing when off): by the key's place on the keyboard, not its letter
+    // (QWERTZ, AZERTY, Dvorak... play as a US keyboard does, as FL)
+    keys::TypingKey typingKey (const juce::KeyPress& key) const;
     void releaseTypingLaunches (bool all); // the released keys' launches (all: every one)
     int lastCurrentPattern = -1; // ("Select first channel with notes when the pattern changes")
     int lastLinkedChannel = -1;  // (Auto select linked modules, round 187a)

+ 186 - 0
src/ui/WindowOwner.cpp

@@ -23,6 +23,12 @@
 #if JUCE_WINDOWS
  #include <windows.h>
 #endif
+#if JUCE_LINUX || JUCE_BSD || JUCE_MAC
+ #include <dlfcn.h>
+#endif
+#if JUCE_MAC
+ #include <CoreFoundation/CoreFoundation.h>
+#endif
 
 namespace lynx
 {
@@ -310,6 +316,186 @@ bool isAboveMainWindow (juce::Component& window)
    #endif
 }
 
+// Where a character key is on the keyboard, for the typing keyboard (FL's table goes by scan code)
+#if JUCE_WINDOWS
+namespace
+{
+// The scan code of the key that types `ch` in `layout` without Shift / AltGr; 0 for none
+int scanCodeOfCharacter (int ch, HKL layout)
+{
+    for (const auto c : { (WCHAR) towlower ((wint_t) ch), (WCHAR) ch })
+    {
+        const auto vk = VkKeyScanExW (c, layout);
+        if (vk == -1 || HIBYTE (vk) != 0) // (no such key, or only with Shift / Ctrl / Alt held)
+            continue;
+        const auto scanCode = (int) MapVirtualKeyExW ((UINT) LOBYTE (vk), MAPVK_VK_TO_VSC, layout);
+        return scanCode > 0 && scanCode < 0x80 ? scanCode : 0;
+    }
+    return 0;
+}
+} // namespace
+
+int scanCodeOfKeyCode (int juceKeyCode)
+{
+    // JUCE's code is MapVirtualKey (vk, MAPVK_VK_TO_CHAR) of the pressed key (upper case for letters). Back to the
+    // key: the layout's virtual key for that character, then that key's scan code.
+    if (juceKeyCode <= ' ' || juceKeyCode > 0xffff)
+        return 0; // (Space, F-keys, arrows, the numpad: not character keys)
+    return scanCodeOfCharacter (juceKeyCode, GetKeyboardLayout (0));
+}
+#elif JUCE_LINUX || JUCE_BSD
+namespace
+{
+// Xlib, looked up at run time (JUCE loads it the same way and keeps its own headers to itself). A connection of its
+// own, used for keyboard questions only and renewed every few seconds, so a keyboard map changed meanwhile is seen.
+struct XKeyboard
+{
+    using OpenDisplay = void* (*) (const char*);
+    using CloseDisplay = int (*) (void*);
+    using DisplayKeycodes = int (*) (void*, int*, int*);
+    using GetState = int (*) (void*, unsigned int, void*);
+    using KeycodeToKeysym = unsigned long (*) (void*, unsigned char, int, int);
+
+    XKeyboard()
+    {
+        if (auto* xlib = dlopen ("libX11.so.6", RTLD_LAZY | RTLD_LOCAL))
+        {
+            openDisplay = (OpenDisplay) dlsym (xlib, "XOpenDisplay");
+            closeDisplay = (CloseDisplay) dlsym (xlib, "XCloseDisplay");
+            displayKeycodes = (DisplayKeycodes) dlsym (xlib, "XDisplayKeycodes");
+            getState = (GetState) dlsym (xlib, "XkbGetState");
+            keycodeToKeysym = (KeycodeToKeysym) dlsym (xlib, "XkbKeycodeToKeysym");
+        }
+    }
+    ~XKeyboard() { close(); }
+
+    void close()
+    {
+        if (display != nullptr)
+            closeDisplay (display);
+        display = nullptr;
+    }
+
+    // The scan code (evdev's key code = Xlib's - 8; the typing block's are the PC scan codes) of the key whose
+    // unshifted keysym in the layout in use (the active XKB group) is `keysym` or `otherKeysym`; 0 for none
+    int scanCodeOf (unsigned long keysym, unsigned long otherKeysym)
+    {
+        if (openDisplay == nullptr || closeDisplay == nullptr || displayKeycodes == nullptr || getState == nullptr || keycodeToKeysym == nullptr)
+            return 0;
+        const auto now = std::time (nullptr);
+        if (display != nullptr && now - opened > 2)
+            close();
+        if (display == nullptr)
+        {
+            display = openDisplay (nullptr);
+            opened = now;
+        }
+        if (display == nullptr)
+            return 0;
+        alignas (16) unsigned char state[64] = {}; // XkbStateRec (18 bytes); its first field is the active group
+        const auto group = getState (display, 0x100 /* XkbUseCoreKbd */, state) == 0 ? (int) state[0] : 0;
+        int first = 8, last = 255;
+        displayKeycodes (display, &first, &last);
+        for (int keycode = std::max (first, 9); keycode <= std::min (last, 8 + 0x7f); ++keycode)
+            if (const auto sym = keycodeToKeysym (display, (unsigned char) keycode, group, 0); sym != 0 && (sym == keysym || sym == otherKeysym))
+                return keycode - 8;
+        return 0;
+    }
+
+    OpenDisplay openDisplay = nullptr;
+    CloseDisplay closeDisplay = nullptr;
+    DisplayKeycodes displayKeycodes = nullptr;
+    GetState getState = nullptr;
+    KeycodeToKeysym keycodeToKeysym = nullptr;
+    void* display = nullptr;
+    std::time_t opened = 0;
+};
+} // namespace
+
+int scanCodeOfKeyCode (int juceKeyCode)
+{
+    // JUCE's code is the character the key types. Back to the key: the key whose keysym is that character (Latin-1
+    // keysyms are the characters; the others' are 0x01000000 + the code point, which leaves out alphabets that have
+    // older keysyms of their own: those keys stay by character)
+    if (juceKeyCode <= ' ' || juceKeyCode > 0x10ffff)
+        return 0;
+    static XKeyboard keyboard;
+    const auto keysymOf = [] (int ch) { return (unsigned long) (ch < 0x100 ? ch : 0x01000000 + ch); };
+    return keyboard.scanCodeOf (keysymOf ((int) juce::CharacterFunctions::toLowerCase ((juce::juce_wchar) juceKeyCode)), keysymOf (juceKeyCode));
+}
+#elif JUCE_MAC
+int scanCodeOfKeyCode (int juceKeyCode)
+{
+    // JUCE's code is the key's character without modifiers. Back to the key: the virtual key code (a place on the
+    // keyboard: kVK_ANSI_*) whose character in the current layout is that one, asked from the Text Input Sources /
+    // UCKeyTranslate. Those live in Carbon's HIToolbox, which LYNX does not link: looked up at run time, and when
+    // anything is missing the answer is 0 (the typing keyboard then goes by character, as before).
+    if (juceKeyCode <= ' ' || juceKeyCode > 0xffff)
+        return 0;
+    struct Api
+    {
+        using CopyLayout = void* (*)();
+        using GetProperty = void* (*) (void*, CFStringRef);
+        using KbdType = std::uint8_t (*)();
+        using Translate = std::int32_t (*) (const void*, std::uint16_t, std::uint16_t, std::uint32_t, std::uint32_t, std::uint32_t, std::uint32_t*,
+                                            unsigned long, unsigned long*, std::uint16_t*);
+        CopyLayout copyLayout = nullptr;
+        GetProperty getProperty = nullptr;
+        KbdType kbdType = nullptr;
+        Translate translate = nullptr;
+        CFStringRef* layoutDataKey = nullptr;
+        Api()
+        {
+            if (auto* carbon = dlopen ("/System/Library/Frameworks/Carbon.framework/Carbon", RTLD_LAZY | RTLD_LOCAL))
+            {
+                copyLayout = (CopyLayout) dlsym (carbon, "TISCopyCurrentKeyboardLayoutInputSource");
+                getProperty = (GetProperty) dlsym (carbon, "TISGetInputSourceProperty");
+                kbdType = (KbdType) dlsym (carbon, "LMGetKbdType");
+                translate = (Translate) dlsym (carbon, "UCKeyTranslate");
+                layoutDataKey = (CFStringRef*) dlsym (carbon, "kTISPropertyUnicodeKeyLayoutData");
+            }
+        }
+        bool ok() const { return copyLayout != nullptr && getProperty != nullptr && kbdType != nullptr && translate != nullptr && layoutDataKey != nullptr; }
+    };
+    static const Api api;
+    if (! api.ok())
+        return 0;
+    // kVK_ANSI_* (0x00..0x32) -> PC scan code; 0: not a key of the typing block
+    static const std::uint8_t scanOfVirtualKey[] = {
+        0x1E, 0x1F, 0x20, 0x21, 0x23, 0x22, 0x2C, 0x2D, 0x2E, 0x2F, 0x00, 0x30, 0x10, 0x11, 0x12, 0x13, // A S D F H G Z X C V - B Q W E R
+        0x15, 0x14, 0x02, 0x03, 0x04, 0x05, 0x07, 0x06, 0x0D, 0x0A, 0x08, 0x0C, 0x09, 0x0B, 0x1B, 0x18, // Y T 1 2 3 4 6 5 = 9 7 - 8 0 ] O
+        0x16, 0x1A, 0x17, 0x19, 0x00, 0x26, 0x24, 0x28, 0x25, 0x27, 0x2B, 0x33, 0x35, 0x31, 0x32, 0x34, // U [ I P Ret L J ' K ; \ , / N M .
+        0x00, 0x00, 0x29                                                                                // Tab Space `
+    };
+    auto* source = api.copyLayout();
+    if (source == nullptr)
+        return 0;
+    int found = 0;
+    if (const auto data = (CFDataRef) api.getProperty (source, *api.layoutDataKey); data != nullptr)
+    {
+        const auto wanted = juce::CharacterFunctions::toLowerCase ((juce::juce_wchar) juceKeyCode);
+        for (std::uint16_t vk = 0; vk < (std::uint16_t) std::size (scanOfVirtualKey) && found == 0; ++vk)
+        {
+            std::uint32_t deadKeys = 0;
+            unsigned long length = 0;
+            std::uint16_t chars[4] = {};
+            if (scanOfVirtualKey[vk] != 0
+                && api.translate (CFDataGetBytePtr (data), vk, 0 /* kUCKeyActionDown */, 0, api.kbdType(), 1 /* kUCKeyTranslateNoDeadKeysMask */, &deadKeys,
+                                  4, &length, chars) == 0
+                && length == 1 && juce::CharacterFunctions::toLowerCase ((juce::juce_wchar) chars[0]) == wanted)
+                found = scanOfVirtualKey[vk];
+        }
+    }
+    CFRelease ((CFTypeRef) source);
+    return found;
+}
+#else
+int scanCodeOfKeyCode (int)
+{
+    return 0;
+}
+#endif
+
 void forceForegroundForTest (juce::Component& window)
 {
    #if JUCE_WINDOWS

+ 6 - 0
src/ui/WindowOwner.h

@@ -67,6 +67,12 @@ void fitAllWindowsOnScreen();
 // reachable; a content that fits is returned as it is. The viewport follows the content's later size changes.
 std::unique_ptr<juce::Component> fitContentToScreen (std::unique_ptr<juce::Component> content);
 
+// The PC scan code (set 1, core/KeyMap.h typingpiano::usKeyOfScanCode) of the key that gives JUCE's key code
+// `juceKeyCode` in the keyboard layout in use now; 0 when it is not a character key or the place can't be told. JUCE's
+// key codes are the key's unshifted character ('Y' for the key left of X on a German keyboard): the typing keyboard
+// asks for the key's place with this (FL goes by scan code).
+int scanCodeOfKeyCode (int juceKeyCode);
+
 // --windowtest only: makes `window` the foreground window even when LYNX was started in the background.
 void forceForegroundForTest (juce::Component& window);
 

+ 121 - 0
tests/TypingPlace190bmTests.inc

@@ -0,0 +1,121 @@
+// Round 190bm (Discord report, German keyboard: "Z and Y are swapped, annoying if you use the keyboard as a keyboard"):
+// the typing keyboard goes by the key's place, not its letter, as FL's does (FL's key table is indexed by the scan
+// codes 2..0x35, FUN_01182670 / FUN_011828c0, REA round 169f). The UI asks the OS for the scan code of the key that
+// gives a character; here simulated layouts stand in for the OS. Included from tests.cpp.
+
+namespace typingplace190bm
+{
+// What each key of the typing block types without Shift, in the order of a US keyboard's
+// 1234567890-= QWERTYUIOP[] ASDFGHJKL;' ` \ ZXCVBNM,./ (Latin-1 code points, letters upper case as the UI's key codes)
+using Layout = std::vector<int>;
+inline const char usKeys[] = "1234567890-=QWERTYUIOP[]ASDFGHJKL;'`\\ZXCVBNM,./";
+
+inline Layout us()
+{
+    return Layout (std::begin (usKeys), std::end (usKeys) - 1);
+}
+inline Layout qwertz() // German: Z and Y swapped, sharp s, umlauts
+{
+    return { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 0xdf, 0xb4, 'Q', 'W', 'E', 'R', 'T', 'Z', 'U', 'I', 'O', 'P', 0xfc, '+',
+             'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 0xf6, 0xe4, '^', '#', 'Y', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '-' };
+}
+inline Layout azerty() // French: A/Q and Z/W swapped, M right of L, digits only with Shift
+{
+    return { '&', 0xe9, '"', '\'', '(', '-', 0xe8, '_', 0xe7, 0xe0, ')', '=', 'A', 'Z', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '^', '$',
+             'Q', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 0xf9, 0xb2, '*', 'W', 'X', 'C', 'V', 'B', 'N', ',', ';', ':', '!' };
+}
+inline Layout dvorak()
+{
+    return { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '[', ']', '\'', ',', '.', 'P', 'Y', 'F', 'G', 'C', 'R', 'L', '/', '=',
+             'A', 'O', 'E', 'U', 'I', 'D', 'H', 'T', 'N', 'S', '-', '`', '\\', ';', 'Q', 'J', 'K', 'X', 'B', 'M', 'W', 'V', 'Z' };
+}
+
+// The OS's answer for a layout: the scan code of the key that types `keyCode` (either case), 0 for none
+inline lynx::keys::typingpiano::ScanCodeLookup lookupOf (Layout layout)
+{
+    return [layout = std::move (layout)] (int keyCode) {
+        const auto fold = [] (int c) { return c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c; };
+        for (std::size_t i = 0; i < layout.size(); ++i)
+            if (fold (layout[i]) == fold (keyCode))
+                return lynx::keys::typingpiano::scanCodeOfUsKey (usKeys[i]);
+        return 0;
+    };
+}
+} // namespace typingplace190bm
+
+TEST (typingplace190bm_scan_codes_are_the_us_keyboard)
+{
+    using namespace lynx::keys::typingpiano;
+    // PC set 1 (= evdev): 1 = 0x02, Q = 0x10, A = 0x1E, ` = 0x29, \ = 0x2B, Z = 0x2C, / = 0x35
+    CHECK (usKeyOfScanCode (0x02) == '1' && usKeyOfScanCode (0x0D) == '=' && usKeyOfScanCode (0x10) == 'Q' && usKeyOfScanCode (0x1B) == ']');
+    CHECK (usKeyOfScanCode (0x1E) == 'A' && usKeyOfScanCode (0x28) == '\'' && usKeyOfScanCode (0x29) == '`' && usKeyOfScanCode (0x2B) == '\\');
+    CHECK (usKeyOfScanCode (0x2C) == 'Z' && usKeyOfScanCode (0x15) == 'Y' && usKeyOfScanCode (0x35) == '/');
+    // Backspace, Tab, Enter, Ctrl, the left Shift, the ISO key and anything outside: no key of the block
+    for (int scan : { 0, 1, 0x0E, 0x0F, 0x1C, 0x1D, 0x2A, 0x36, 0x39, 0x56, -3, 400 })
+        CHECK (usKeyOfScanCode (scan) == 0);
+    // every key of the block has one scan code, and back
+    std::set<int> seen;
+    for (const char* k = typingplace190bm::usKeys; *k != 0; ++k)
+    {
+        const auto scan = scanCodeOfUsKey (*k);
+        CHECK (scan >= 0x02 && scan <= 0x35 && usKeyOfScanCode (scan) == *k);
+        seen.insert (scan);
+    }
+    CHECK (seen.size() == 47);
+    CHECK (scanCodeOfUsKey ('z') == 0x2C && scanCodeOfUsKey (0) == 0 && scanCodeOfUsKey (' ') == 0);
+}
+
+TEST (typingplace190bm_every_layout_plays_as_the_us_keyboard)
+{
+    using namespace lynx::keys;
+    using namespace typingplace190bm;
+    const std::pair<const char*, Layout> layouts[] = { { "US", us() }, { "QWERTZ", qwertz() }, { "AZERTY", azerty() }, { "Dvorak", dvorak() } };
+    for (const auto& [name, layout] : layouts)
+    {
+        CHECK (layout.size() == 47);
+        const auto lookup = lookupOf (layout);
+        for (std::size_t i = 0; i < layout.size(); ++i)
+        {
+            // the key at place i types layout[i]; it plays what the US key of that place plays, in every FL layout
+            const auto place = typingpiano::physicalKey (layout[i], lookup);
+            CHECK (place == usKeys[i]);
+            for (int l = 0; l < typingpiano::layoutCount(); ++l)
+            {
+                const auto got = typingPianoKey (letterOfKeyCode (place), 4, 0, l), want = typingPianoKey (usKeys[i], 4, 0, l);
+                CHECK (got.taken == want.taken && got.notes == want.notes);
+            }
+        }
+    }
+}
+
+TEST (typingplace190bm_german_keyboard_z_row_starts_left_of_x)
+{
+    using namespace lynx::keys;
+    using namespace typingplace190bm;
+    const auto piano = typingpiano::pianoLayout();
+    const auto play = [piano] (int keyCode, const typingpiano::ScanCodeLookup& lookup) {
+        return typingPianoKey (letterOfKeyCode (typingpiano::physicalKey (keyCode, lookup)), 4, 0, piano);
+    };
+    // the report: on QWERTZ the key left of X types Y. It is the Z row's first note (MIDI 48), and the key between T and
+    // U (types Z) is the Q row's A (MIDI 69). By character they were the other way round.
+    const auto german = lookupOf (qwertz());
+    CHECK (play ('Y', german).notes == std::vector<int> { 48 });
+    CHECK (play ('Z', german).notes == std::vector<int> { 69 });
+    CHECK (play ('y', german).notes == std::vector<int> { 48 }); // (Linux hands the lower-case character)
+    CHECK (typingPianoNote ('Y') == 69 && typingPianoNote ('Z') == 48); // (the US keyboard, unchanged)
+    // AZERTY: the Q row starts at the key that types A; the number row's black keys play without Shift (2 = e acute)
+    const auto french = lookupOf (azerty());
+    CHECK (play ('A', french).notes == std::vector<int> { 60 });
+    CHECK (play ('W', french).notes == std::vector<int> { 48 });
+    CHECK (play (0xe9, french).notes == std::vector<int> { 61 });
+    CHECK (play (',', french).notes == typingPianoKey ('M', 4, 0, piano).notes);
+    // Dvorak: the key at Z's place types a semicolon
+    CHECK (play (';', lookupOf (dvorak())).notes == std::vector<int> { 48 });
+
+    // a key whose place the OS can't tell stays by character (as before); so does everything without a lookup
+    CHECK (typingpiano::physicalKey ('Z', [] (int) { return 0; }) == 'Z');
+    CHECK (typingpiano::physicalKey ('Z', nullptr) == 'Z');
+    // a key at a place outside the block (the ISO key left of Z, scan 0x56) is no typing key, whatever it types
+    CHECK (typingpiano::physicalKey ('Z', [] (int) { return 0x56; }) == 0);
+    CHECK (! play ('<', [] (int) { return 0x56; }).taken);
+}

+ 1 - 0
tests/tests.cpp

@@ -17329,6 +17329,7 @@ TEST (fl_low_lifter_matches_fl_engine)
 #include "Speech168bTests.inc"
 #include "Design168pTests.inc"
 #include "Typing168tTests.inc"
+#include "TypingPlace190bmTests.inc"
 #include "GrossBeat168mTests.inc"
 #include "Maximus168xTests.inc"
 #include "Rec168xTests.inc"