I barely dare to pronounce it (superstition): SOLVED
(I sincerely hope, permanently, but one must wait at least two or three weeks to be certain) (this bug has taken the nasty habit to appear randomly during "decades" and could perfectly still be there).
Something has obviously changed in OSX, anyway. I develop:
NB: OSX 10.13.5 (and maybe a bit previous) ONLY. This old trick advised during years with no result HASN'T worked (ever) with older versions of OSX (see examples further). You're lucky: NOW (maybe) it works.
The only thing that has changed in this (very long) story is OSX itself, to be more precise.
To solve the problem, you must follow these mainstream DIY instructions given a considerable number of times in the past on this forum — a bit too much for something that has NEVER functioned... — regarding this same bug on older versions of OSX (the trick solved the problem for a time, the first time that you applied it... and the situation were coming back to "normal state" (bugged) two or three days later) (and this, on all successive versions of OSX since "Mountain Lion"...) Example: https://discussions.apple.com/thread/7808970
Good news, in OSX 10.13.5 that cur&$#ed .plist file supposedly "corrupted" (by the system itself, which else?) is (suddenly) no more recreated — in any case, not at the same name/place we used to find it, obstinately wallowed, in all the previous years. Don't ask me in what exotic sandbox its little brother is wading today, there are in this forum enough experts of a considerably higher level in programming than me to tell you this (if you really want to know) (personally I prefer to forget it forever, no matter where this thing is located...).
One can however infer that the problem is today solved permanently by this old trick, like it was solved — but always temporarily — with this exactly same old trick, in the past. The only thing having changed being what Apple programmers have (very recently) modified in OSX's Keyboard preferences.
This enormous, long-lasting and sticky bug, so, has ACTUALLY BEEN SOLVED - rather discretely, eh, dudes? — by Apple programmers in one of the most recent updates of OSX.
BUT — unfortunate fate — this didn't help you, obstinate mac user, because this infamous .plist file is STILL in your Library, and that — don't ask me why — the Keyboard preferences panel persists today to take this old b$t#h into account. Therefore you must — still today — remove it.
If you had encountered this f#@&% bug during more than 6 years like me and systematically got as only usual answers: that it was user-related (my fault, so), that I should try to use a new account (how the f#@&% am I supposed to continue to work, cr#@&tin?), "very few other users have this problem" (you bet) and finally the (in)famous "erase your .plist and reset your pram", what has never ever solved the problem since "decades" (Example of question supposedly "solved": https://discussions.apple.com/thread/4966509?answerId=21775327022#21775327022 ), the bl&$@dy .plist being immediately recreated, and the problem systematically coming back a week later, you wouldn't even THINK to redo, ONCE AGAIN, in your most recent version of OSX, this exactly same "erase your .plist and reset your pram" having proven during so many years its inefficiency...
However, this is actually the solution.
Actually, you even had to be multipotential to just even CONSIDER to do that, in opposition of all logic, of all you have learned, and ONLY because it was the only valid solution remaining among a good hundred of others that another brain — even of much higher IQ — would have spent years at checking the validity of all, the ones after the others.
See what I mean? Back to the process:
Here I assume you have already done a complete backup of your precious files (a personal backup) (because if you use Time Machine, it will PUT YOU BACK IN YOUR SYSTEM THAT .PLIST FILE WITH ALL THE REST OF YOUR BACKUP) (get it?) :). So...
— Going "old-fashion" (yes, the EXACTLY same thing you have done with no result a good thousand of times during the last 6 years...), locate the (infamous) .plist file:
/Users/your-user-name/Library/Preferences/com.apple.systempreferences.plist
If by misfortune you don't see any "Library" in your home folder it's because Apple don't want to admit that this is YOUR system, that YOU are the superuser here and that the minimum is that YOU can access to your system files, dammit. In this case, follow the painful — and variable along years — procedure to allow the displaying of your Library. Or just display permanently your hidden files.
- Displace that f&@#% .plist file to your desktop and let it there for the moment.
- Shutdown your Mac.
- Start it while resetting you parameter ram (hold down alt-cmd-P-R at the same time) (people with normally-sized hands will need help of one or two friends) (if you are a sasquatch — or a piano player — it should be ok). Don't hesitate to keep these keys down and let repeat more than one time that funny little chime, it won't break anything. Then (stop kidding and) let the Mac start up.
— Check if nothing particularly ugly happened to your system (it should be the case) (no reason the displacement of this old .plist file makes any difference in your system, because your keyboard preferences are stored "elsewhere" today) and then, trash definitively that shame for the Humanity of .plist file.
— NB: STARTING FROM THIS DATE/HOUR/MINUTE NEVER (EVER) COME BACK, IN TIME MACHINE, TO ANY OLDER STATE THAN JUST NOW. Otherwise the f&@#% file will be back into your system with all the rest of your (much more useful) old things. SAME WARNING IF YOU'RE DOING A FRESH INSTALL OF A BRAND NEW MAC WITH YOUR PREVIOUS APPS AND FILES FROM TIME MACHINE CLOUD. THIS OLD .PLIST FILE WILL COME TO YOUR BRAND NEW SYSTEM WITH ALL THE REST.
— Open your Keyboard preferences panel, now. NOTE THAT NOW SOMETHING HAS CHANGED: "Automatically switch to a document's input source" is NOW visible (it wasn't, previously) (you know, that thing that everybody in the forums told you to uncheck and that you could find nowhere). IT IS THERE, NOW. And — even if the bug doesn't come from that — you can now DESELECT that option, which is selected by default (!...) (unless, of course, you really want your system to live definitively into the House of the Mad Hatter and nevermore in your life be able to determine which of these bl&#@%dy keyboard maps has been chosen arbitrarily for you in each and every application you open...) (kind of: qwerty in the finder, azerty in your word processing app, for instance...) (yes, I know: tastes and colors...) (but IMO the dude who has invented that thing deserves to be summarily executed).
— Set your keyboard preferences as YOU want them to be (at last!, sigh of relief) and reboot.
— Result: To date, this SEEMS to have solved the problem permanently (but as, already when it wasn't solved, the bug only used to appear randomly...) (To Be Continued, so...)
Regards to all.