Simulate power management keys

Hi!

For a project I am trying to shut a PC down with the following scan codes:

Set-1 make/brake Set-2 make/brake
Power e0 5e / e0 de e0 37 / e0 f0 37
Sleep e0 5f / e0 df e0 3f / e0 f0 3f
Wake e0 63 / e0 e3 e0 5e / e0 f0 5e

I've asked this question over several forums. But I can not get it to work. I've managed to shut the PC down with a CMD command. So when I press a button the Arduino will send a keyboard.press. That works but I really have to use the above called codes. Futher I tried to define the power management key's in the USB keyboard library by adding power/sleep/wake = 0x81/0x82/0x83 . But unfortunately the Arduino IDE doesn't recognize them: they stay black while the standard keys turn blue.

My question is: how can I simulate the power management key's? I think it is good to mention that I am a beginner at this.

Regards,
/Zwilk

interesting project,
maybe start with posting your code so we can see how you did the first part?

robtillaart:
interesting project,
maybe start with posting your code so we can see how you did the first part?

Hi Rob, thanks for the fast reply! Sorry for not posting the code I used so far. Here is it:

int button_pin = 2;
int led = 11;

void setup() {
  pinMode(button_pin, INPUT);
  pinMode(led, OUTPUT);
}

void loop() {
  in button_state = digitalRead(button_pin);
 if (button_State == HIGH) {
    digitalWrite(led, HIGH);
    Keyboard.press(KEY_LEFT_GUI);
    Keyboard.releaseAll();
    delay(250);
    Keyboard.press(KEY_RIGHT_ARROW);
    Keyboard.releaseAll();
    delay(250);
    Keyboard.press(KEY_ENTER);
    Keyboard.releaseAll();
   } else {}
}

This code works with a limited amount of OS'es. So I tried the following:

#include <usb_keyboard>

int led = 11;

void setup() {
  pinMode(led, OUTPUT);
  Keyboard.begin();
}

void loop() {
  digitalWrite(led, HIGH);
  Keyboard.press(KEY_POWER/0x81/'0x81'/81/129/'129');
  delay(10);
  Keyboard.releaseAll();
  delay(5000);
}

So in the library I defined the power management keys with the following information found on USB HID usage table.

0x81 System Power Down
0x82 System Sleep
0x83 System Wake Up

And in the Keyboard.press command I try to call the System Power Down but nothing happened.

Do you have any idea how to use these hex code to shut down any OS? Is this information even correct?

I hope I informed you enough!

/Zwilk