# How to emulate a usb keyboard

**URL:** <https://community.particle.io/t/how-to-emulate-a-usb-keyboard/54875>\
**Category:** Firmware\
**Created:** [February 24, 2020, 5:47pm UTC](https://community.particle.io/t/how-to-emulate-a-usb-keyboard/54875 "2020-02-24T17:47:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TimS](https://avatars.discourse-cdn.com/v4/letter/t/7ea924/32.png) [@TimS](https://community.particle.io/u/TimS)\
**Post date:** [February 24, 2020, 5:47pm UTC](https://community.particle.io/t/how-to-emulate-a-usb-keyboard/54875/1 "2020-02-24T17:47:12Z")

</div>

I thought this was going to be easy, but I seem to be struggling with the basics. I want to use the keyboard.printlnf command to send keystrokes to an open notepad on my PC - like a simple console. I have my photon connected to my PC over USB and have loaded this code for testing. I can see by the color change on the status LED when I have hit the input, but the keypoard.print command doesn’t seem to do anything. :

```cpp
int button = D7;
STARTUP(Keyboard.begin());

void setup() {
    pinMode(button, INPUT_PULLDOWN);
    delay(2000);
}

void loop() {
    if(digitalRead(button) == HIGH){
        RGB.control(true);
        RGB.brightness(64);
        RGB.color(255, 0, 0); //red
        Keyboard.printlnf("Test", millis());
        delay(1000);
        RGB.control(false);
    }
    while(digitalRead(button) == HIGH) {
        delay(500);
    }
}

```

I have loaded the Photon 1.4.4 firmware and I am running Windows10 on my PC . What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [February 24, 2020, 6:22pm UTC](https://community.particle.io/t/how-to-emulate-a-usb-keyboard/54875/2 "2020-02-24T18:22:31Z")

</div>

I have tried this slightly simplified code and that works for me just fine with 1.4.4 on Win10

_(I’m using the SETUP button instead of an external button on D7)_

```cpp
STARTUP(Keyboard.begin());

void loop() {
  if(!digitalRead(BTN)) {
    RGB.control(true);
    RGB.brightness(64);
    RGB.color(255, 0, 0); //red
    Keyboard.printlnf("Test %d", millis());
    while(!digitalRead(BTN));
    RGB.control(false);
  }
}

```

---

<div class="post-metadata">

**Author:** ![TimS](https://avatars.discourse-cdn.com/v4/letter/t/7ea924/32.png) [@TimS](https://community.particle.io/u/TimS)\
**Post date:** [February 24, 2020, 8:53pm UTC](https://community.particle.io/t/how-to-emulate-a-usb-keyboard/54875/3 "2020-02-24T20:53:42Z")

</div>

Thanks!! It turned out the code worked all along, I apparently have a stack of power only USB cables. I finally found one with data as well and it is working great now.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/3/2/3291e3c9351789fe8620ae5bcec8d3fec67ff221.png) [@system](https://community.particle.io/u/system)\
**Post date:** [August 25, 2020, 8:53am UTC](https://community.particle.io/t/how-to-emulate-a-usb-keyboard/54875/4 "2020-08-25T08:53:52Z")

</div>

Closed on August 25, 2020, 8:53am UTC

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