Arduino Leonardo Keyboard library problems

Hello.

I recently purchased a cheap Leonardo and I'm trying to use the Keyboard.h library to emulate a keyboard. I am using a nordic keyboard layout (Finnish) and ran into some problems because the arduino only sends keystrokes using US layout.

I have been able to connect every other symbol (either through the Keyboard.cpp file or with the help of the .ino file) correctly except for these < > |
These are typed using one button (different combinations: shift and Alt gr). Can I even access this button through the arduino or am I trying to do something impossible?

Any help would be much appreciated!

Did you try filtering it on the output side.

If (symbol == '>');
    symbol = '(Finnish symbol)';

This is what I did for symbols that used alt gr as the library doesn't support adding altgr into the Keyboard.cpp file. However I have not found a symbol on the Finnish keyboard that would correspond to the '<' symbol on the US keyboard.

I see that those are all on one key on a Finnish keyboard, at least the one I'm looking at.
I fact, it looks like an extra key between the shift and the Z.
That's a pickle.

Yes correct, they are all on one key. I am beginning to think that there is no corresponding key to the '<' key.

Can you get the raw codes from the KB?

I have tried that. I think that the problem is that the US keyboard doesn't have a key where the < key is on the Finnish keyboard.

Try this:
GitHub - Necr0tizing/ArduinoKeyboardLayouts: Arduino keyboard languages for easy swapping of keyboard layout codes to match your language, ideal for non US users

Will try this once I get home. Thanks!

Absolutely
Hope it helps
Please post your results to help future users too.

@potatoprogrammer, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with your project :wink: See About the Installation & Troubleshooting category.

Worked! Or partially at least. You still need to define all characters that require the altgr key in the .ino file, but knowing the hexadecimal for '<' made it possible to add all symbols to the keyboard.

Here is how I defined the altgr characters to the code. You can probably get the idea without the whole code.

 if(b.length() == 1 && b[0] == '$')
  {
    Keyboard.press(KEY_RIGHT_ALT);
    Keyboard.press('4');
    Keyboard.releaseAll();
  }
  else if(b.length() == 1 && b[0] == '@')
  {
    Keyboard.press(KEY_RIGHT_ALT);
    Keyboard.press('2');
    Keyboard.releaseAll();
  }
  else if(b.length() == 1 && b[0] == '{')
  {
    Keyboard.press(KEY_RIGHT_ALT);
    Keyboard.press('7');
    Keyboard.releaseAll();
  }
  else if(b.length() == 1 && b[0] == '[')
  {
    Keyboard.press(KEY_RIGHT_ALT);
    Keyboard.press('8');
    Keyboard.releaseAll();
  }
  else if(b.length() == 1 && b[0] == ']')
  {
    Keyboard.press(KEY_RIGHT_ALT);
    Keyboard.press('9');
    Keyboard.releaseAll();
  }
  else if(b.length() == 1 && b[0] == '}')
  {
    Keyboard.press(KEY_RIGHT_ALT);
    Keyboard.press('0');
    Keyboard.releaseAll();
  }
  else if(b.length() == 1 && b[0] == '\\')
  {
    Keyboard.press(KEY_RIGHT_ALT);
    Keyboard.press('+');
    Keyboard.releaseAll();
  }
  else if(b.length() == 1 && b[0] == '|')
  {
    Keyboard.press(KEY_RIGHT_ALT);
    Keyboard.press('<');
    Keyboard.releaseAll();
  }

Awesome.
Glad you got it figured out.
I found that solution by searching "arduino finnish keyboard.h"
Hope that helps with future language barriers.

Happy programming!

1 Like

I had been only searching with "keyboard.cpp". Need to remember to use the package name xd

1 Like

Created a better alternative to the Keyboard.cpp file.

Can be found here: https://github.com/nuuttihenriksson/Keyboard

Hopefully helps someone.

1 Like

What did you improve?

Added the possibility to use the "alt gr" key in the ascii map. It is used at least with nordic keyboards to reach certain characters such as € $ and @.

1 Like

Excellent :+1:

1 Like