Support for International keyboards
When I press the + key on my keyboard, - is echoed to the log file.
Evidently, an American keyboard is assumed.
Suggest to add support for International keyboards.
Suppose there is a system call that can do the translation.
Yes, US layout is hard-coded. See:
// The following method converts the key code returned by each keypress as
// a human readable key code in const char format.
const char *convertKeyCode(int keyCode, bool shift, bool caps) {
switch ((int) keyCode) {
case 0: return shift || caps ? "A" : "a";
case 1: return shift || caps ? "S" : "s";
case 2: return shift || caps ? "D" : "d";
case 3: return shift || caps ? "F" : "f";
case 4: return shift || caps ? "H" : "h";
case 5: return shift || caps ? "G" : "g";
case 6: return shift || caps ? "Z" : "z";
case 7: return shift || caps ? "X" : "x";
case 8: return shift || caps ? "C" : "c";
case 9: return shift || caps ? "V" : "v";
case 11: return shift || caps ? "B" : "b";
case 12: return shift || caps ? "Q" : "q";
case 13: return shift || caps ? "W" : "w";
case 14: return shift || caps ? "E" : "e";
case 15: return shift || caps ? "R" : "r";
case 16: return shift || caps ? "Y" : "y";
case 17: return shift || caps ? "T" : "t";
case 18: return shift ? "!" : "1";
case 19: return shift ? "@" : "2";
case 20: return shift ? "#" : "3";
...
I could change 19 and 20 to " and £ for the UK layout for example. One could also edit this to flip QWERTY to AZERTY (#14), but the plain letters are the easy bit. What about accents and deadkeys? Logging at a different point in the OS might give you characters...
It makes me think recording the numerical keycodes would be simpler, and/or post-processing the keylog in a scripting language aware of the actual layout in use?
Ask https://labs.perplexity.ai/: Does macOS have a system call to convert numeric keyboard values (0=A, 1=S, etc.) to whatever international keyboard the user has installed?
Stale