How to turn off pc with leonardo pro micro.

hi, I'm a beginner and I have a problem with keyboard.write

void setup(){

  // make pin 2 an input and turn on the 
  // pullup resistor so it goes high unless
  // connected to ground:
    delay(200);
    Keyboard.press(0x83);
    delay(1000);
    Keyboard.press('r');
    delay(1000);
    Keyboard.releaseAll();
    delay(1000);
  //  Keyboard.print("cmd");
  //  delay(1000);
  //  Keyboard.write(0xB0);
  //  delay(1000);
    Keyboard.print("shutdown /s /t100 /f");
    delay(1000);
    Keyboard.write(0xB0);
    delay(1000);
}

arduino code is keyboard.print("shutdown /s /t100 /f"); and when I run the program than arduino print in commander shutdown -s -t+éé -f

arduino can't write "shutdown /s /t100 /f"

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

vypnout_pc.ino (1.24 KB)

And that problem is ..?

Please remember to use code tags when posting code.

Hi, I'm a beginner and I have a problem with keyboard.h usage.
I am trying to open Win+R and run command shutdown /s /t100 /f, but when I run my code I get shutdown -s -t+éé -f instead.
What am I doing wrong?
My Windows is localized to CZ, Windows-1250 charset.

Thank you.

void setup(){

  // make pin 2 an input and turn on the 
  // pullup resistor so it goes high unless
  // connected to ground:
    delay(200);
    Keyboard.press(0x83);
    delay(1000);
    Keyboard.press('r');
    delay(1000);
    Keyboard.releaseAll();
    delay(1000);
  //  Keyboard.print("cmd");
  //  delay(1000);
  //  Keyboard.write(0xB0);
  //  delay(1000);
    Keyboard.print("shutdown /s /t100 /f");
    delay(1000);
    Keyboard.write(0xB0);
    delay(1000);
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

arduino code is keyboard.print("shutdown /s /t100 /f"); and when I run the program than arduino print in commander shutdown -s -t+éé -f

arduino can't write "shutdown /s /t100 /f"

Perhaps the / are not being read as / but are interpreted as something else.

What am I doing wrong?

You give the answer yourself:

My Windows is localized to CZ, Windows-1250 charset.

The constant asciimap in Keyboard.cpp implements an ASCII to keycode conversion for the US American keyboard layout only. You have to adapt that to your own layout if you want to use it with your system or you have to change the keyboard layout of your PC to US American.

My guess is that you have a non-US keyboard layout, which has different keycodes. The Keyboard class sends keycodes to the PC, not characters, and your PC is interpreting the keycodes as different characters than you expect them to be.

A workaround is to use the US keyboard-layout to find the mapping between characters and physical keys.

If you look at a US keyboard you will see a 'y' on the location of 'z' for the CZ keyboard.

Example:

Keyboard.print("y")

This will result in 'z' on a PC with Czech keyboard-driver.

@tomeeq, do not cross-post. Threads merged.