0

I can't seem to find a way to change the keyboard layot on my Arduino USB.. I have tried changing it inside the IDE. Still doesn't work, i need a Danish layout. This is my code:

#include <Keyboard.h>

void setup() {
  Keyboard.begin();
}

void loop() {
    delay (2000);
    Keyboard.press(KEY_LEFT_GUI);
    delay (400);
    Keyboard.press('r');
    Keyboard.releaseAll();
    delay (400);
    Keyboard.println("cmd");
    Keyboard.press(KEY_RETURN);
    delay (400);
    Keyboard.println("start chrome https://www.youtube.com/watch?v=dQw4w9WgXcQ&ab_channel=RickAstleyVEVO");
    delay (400);
    Keyboard.press(KEY_RETURN);
    delay (400);
    Keyboard.releaseAll();
    Keyboard.press(KEY_LEFT_GUI);
    delay (400);
    Keyboard.press('r');
    delay (400);
    Keyboard.println("cmd");
    Keyboard.press(KEY_RETURN);
    Keyboard.releaseAll();
    delay (400);
    Keyboard.println("start chrome https://fakeupdate.net/win10ue/");
    delay (400);
    Keyboard.press(KEY_RETURN);
    delay (400);
    Keyboard.releaseAll();
    Keyboard.press(KEY_F11);
    
}

But my output insede cmd is "start chrome httpsÆ--www.youtube.com-watch_v´dQw4w9WgXcQ/ab?channel´RickAstleyVEVO"

2
  • You're trying to start Chrome on an Arduino? What does the other URL print? Commented Nov 30, 2020 at 23:13
  • The other one is supposed to open yet another link in chrome Commented Dec 1, 2020 at 8:34

2 Answers 2

1

As your PC has a Danish layout your Arduino needs to send the character for ":", "/", "?" and "&" after being mapped to a Danish layout.

This can be done be changing your Arduino code to send the character ">" in place of a colon, "-" instead of a forward slash, "_" instead of a question mark, "^" for the ampersand.

Explanation

A quick peek at the implementation of the keyboard library shows that it does not send ASCII. See keyboard.cpp at https://github.com/arduino-libraries/Keyboard/blob/master/src/Keyboard.cpp.

The relevant snippets of code are:

0x24|SHIFT,    // &
0x38,          // /
0x33|SHIFT,      // :
0x38|SHIFT,      // ?

The hex numbers here are USB HID Usage Ids. Essentially a "scan code" that is sent to the USB driver. This scan code is mapped to a character by your keyboard layout.

e.g. The Arduino keyboard library takes the ":" and sends the Usage Id 0x33 with a shift modifier over the USB connection. At the other end this usage id is mapped to a character using the keyboard layout. A Danish layout maps 0x33 with a shift modifier to "Æ".

If the Arduino keyboard library sees ">" then it sends the usage id 0x37 with a shift modifier. The Danish layout will map this to the ":" character.

References

Sign up to request clarification or add additional context in comments.

Comments

0

I also have a Danish keyboard, and what worked for me was to put this at the top of the script:

#define HID_CUSTOM_LAYOUT
#define LAYOUT_DANISH

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.