Can't use any special characters

Hey, I want to use / or ' but it always prints # or ß or something like that...

How do I Keyboard.print this?

What keyboard locale is your PC configured for?

German

and it just prints an ß instead of an / or a ) instead of (

what's your code? what's your arduino?

if it's with the Keyboard library, try Keyboard.begin(KeyboardLayout_de_DE); instead of just Keyboard.begin(); you might have (just guessing)

1 Like

image

I use the Arduino leonardo and my code is just Keyboard.begin() and .print("some/text")

it's documented here

and the languages are in the source code for the library

do you have the latest packages installed?

Hi @immuc. This keyboard layout support feature was added in the latest release of the Keyboard library. Your error indicates you are using an older version of the library that does not have the feature.

The fix is to update the library by following these instructions:

Please try this:

  1. Select Sketch > Include Library > Manage Libraries... from the Arduino IDE menus.
  2. Wait for the update to finish.
  3. In the "Filter your search" field, type keyboard.
  4. Press Enter.
  5. Scroll down through the list of libraries until you see "Keyboard by Arduino". Click on it.
  6. Click the Update button.
  7. Wait for the installation to finish.
  8. Click the Close button.

Now try uploading your sketch to your Leonardo again. This time it should compile without the error and work as expected.

Still doesn't work. Here is my full code:

#include <Keyboard.h>
//#include <KeyboardLayout.h>

#include <HID-Project.h>
#include <HID-Settings.h>

// Utility function
void typeKey(int key){
  Keyboard.press(key);
  delay(50);
  Keyboard.release(key);
}

void setup()
{
  // Start Keyboard and Mouse
  AbsoluteMouse.begin();
  Keyboard.begin();

  // Start Payload
  delay(3000);

  Keyboard.press(KEY_LEFT_GUI);
  Keyboard.press(114);
  Keyboard.releaseAll();

  delay(500);

  Keyboard.print("iexplore -k http://fakeupdate.net/win10/index.html");

  typeKey(KEY_ENTER);

  // End Payload

  // Stop Keyboard and Mouse
  Keyboard.end();
  AbsoluteMouse.end();
}

// Unused
void loop() {}

and it doesn't even work...
here is the full Error message:

In file included from c:\users\User\documents\arduino\libraries\hid-project\src\hid-apis\KeyboardAPI.h:29:0,
                 from c:\users\User\documents\arduino\libraries\hid-project\src\hid-apis\defaultkeyboardapi.h:27,
                 from C:\Users\User\Documents\Arduino\libraries\HID-Project\src/SingleReport/BootKeyboard.h:30,
                 from C:\Users\User\Documents\Arduino\libraries\HID-Project\src/HID-Project.h:50,
                 from C:\Users\User\Desktop\ducky4arduino-master\own_scripts\rickroll\rickroll.ino:4:
c:\users\User\documents\arduino\libraries\hid-project\src\keyboardlayouts\improvedkeylayouts.h:54:21: note: #pragma message: Using default ASCII layout for keyboard modules
     #pragma message "Using default ASCII layout for keyboard modules"
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:\Users\User\Desktop\ducky4arduino-master\own_scripts\rickroll\rickroll.ino:1:0:
C:\Users\User\Documents\Arduino\libraries\Keyboard\src/Keyboard.h:52:27: error: expected identifier before numeric constant
 #define KEY_RETURN        0xB0
                           ^
c:\users\User\documents\arduino\libraries\hid-project\src\keyboardlayouts\improvedkeylayouts.h:103:5: note: in expansion of macro 'KEY_RETURN'
     KEY_RETURN          = 40, // Alias
     ^~~~~~~~~~
C:\Users\User\Documents\Arduino\libraries\Keyboard\src/Keyboard.h:52:27: error: expected '}' before numeric constant
 #define KEY_RETURN        0xB0
                           ^
c:\users\User\documents\arduino\libraries\hid-project\src\keyboardlayouts\improvedkeylayouts.h:103:5: note: in expansion of macro 'KEY_RETURN'
     KEY_RETURN          = 40, // Alias
     ^~~~~~~~~~
C:\Users\User\Documents\Arduino\libraries\Keyboard\src/Keyboard.h:52:27: error: expected unqualified-id before numeric constant
 #define KEY_RETURN        0xB0
                           ^
c:\users\User\documents\arduino\libraries\hid-project\src\keyboardlayouts\improvedkeylayouts.h:103:5: note: in expansion of macro 'KEY_RETURN'
     KEY_RETURN          = 40, // Alias
     ^~~~~~~~~~
In file included from c:\users\User\documents\arduino\libraries\hid-project\src\hid-apis\KeyboardAPI.h:29:0,
                 from c:\users\User\documents\arduino\libraries\hid-project\src\hid-apis\defaultkeyboardapi.h:27,
                 from C:\Users\User\Documents\Arduino\libraries\HID-Project\src/SingleReport/BootKeyboard.h:30,
                 from C:\Users\User\Documents\Arduino\libraries\HID-Project\src/HID-Project.h:50,
                 from C:\Users\User\Desktop\ducky4arduino-master\own_scripts\rickroll\rickroll.ino:4:
c:\users\User\documents\arduino\libraries\hid-project\src\keyboardlayouts\improvedkeylayouts.h:521:1: error: expected declaration before '}' token
 };
 ^
exit status 1
Fehler beim Kompilieren für das Board Arduino Leonardo.

Btw: I am trying to make a script that automatically opens the website on the PC.

Remove these lines from your sketch:

start simple

#include <Keyboard.h>

void typeKey(int key) {
  Keyboard.press(key);
  delay(100);
  Keyboard.release(key);
}

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

  delay(3000);

  Keyboard.press(KEY_LEFT_GUI);
  Keyboard.press(114);
  delay(100);
  Keyboard.releaseAll();

  delay(500);
  Keyboard.print("iexplore -k http://fakeupdate.net/win10/index.html");
  Keyboard.flush(); // wait for everything to be sent
  typeKey(KEY_RETURN);

  Keyboard.end();
}

void loop() {}

does this compile ?

1 Like

Yes, it does. Wow it works perfectly! Thank you for your help :slight_smile:

I'm sure all the rickrolling victims will be very grateful to you @J-M-L :laughing:

I’m on a Mac, so I would never be worried about seeing Windows 10 trying to be updated by magic

Hopefully victims will learn not to connect stuff to their PC without a bit of thinking :wink:

This library can print really ALL characters of a german keyboard.

check the other library with this testcode:

#include <KeyboardGER2.h>

KeyboardGER2 myKeyBoard;

void setup() {
  delay(2000);
  Serial.begin(115200);
  delay(2000);
  Serial.println( F("Setup-Start") );
  Serial.println( F("For testing keep sending keystrokes in setup") );
  Serial.println( F("setup is executed only ONCE") );
  Serial.println( F("loop repeats execution endlessly") );
  Serial.println( F("which could result in endless keystrokes") );
  Serial.println( F("it is very hard to upload a new code ") );
  Serial.println( F("while your microcontroller keeps sending keystrokes!") );
  Serial.println( F("Set cursor-focus into a empty texteditor to make") );
  Serial.println( F("the key-strokes land in this extra-text") );

  Serial.println("countdown 10 to 0 then send keystrokes...");

  for ( int i = 10; i > 0; i--) {
    Serial.println(i);
    delay(1000);
  }
  myKeyBoard.begin();

  myKeyBoard.typeText("This is a test print all characters:");
  myKeyBoard.SendReturn();
  myKeyBoard.SendReturn();
  myKeyBoard.typeText("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  myKeyBoard.SendReturn();
  myKeyBoard.SendReturn();
  myKeyBoard.typeText("abcdefghijklmnopqrstuvwxyz");
  myKeyBoard.SendReturn();
  myKeyBoard.SendReturn();
  myKeyBoard.typeText("1234567890ß?");
  myKeyBoard.SendReturn();
  myKeyBoard.SendReturn();
  myKeyBoard.typeText("^°§$%&/()=");
  myKeyBoard.SendReturn();
  myKeyBoard.SendReturn();
  myKeyBoard.typeText("²³{[]}\\',;.:-_<|>");
  myKeyBoard.SendReturn();
  myKeyBoard.SendReturn();
}


void loop() {
  // ATTENTION ! Don't lock yourself out !
  // As you are coding to send key-strokes that are just the same as
  // typing on the keyboard
  // whenever you put sending keystrokes in function loop
  // use a button as the condition to send the keystrokes
  // example
  /*
    const byte myButtonPin = 5;
    pinMode(myButtonPin,INPUT_PULLUP); // connect button to ground
    if (digitalRead(myButtonPin == low) { // pressed button means digital low
      // send key strokes
    }

    This ensures that your code is NOT flooding the IDE-Texteditor with keystrokes
    right after plugging in the USB-cable
    this keystroke-flooding could cause that you have a hard time to upload
    new code that stops the flooding
  */

}

best regards Stefan

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.