Help with Keyboard.write combinations Micro

Hi, I am new to the Keyboard.write function and I need to write specific key combinations using my Micro.

These are the 4 combinations I need to write:

  1. 'Windows + 1' 2. 'Shift+N' 3.'Control + 1' 4. 'Control+Alt+C'

When I do for instance, Keyboard.write('Shift+n'); it returns only n and does not press shift.
I am struggling to find a reference for these combinations. Can anyone please help?

Thank you!

TRY Reading The Functions Manual

Thank you for your awnsers. I did try this, however, it is unclear how to use these?

I tried:

Keyboard.press('KEY_SHIFT');
Keyboard.press('n');
delay(1000);
Keyboard.release('KEY_SHIFT');
Keyboard.release('n');

}//

With this code I just get 'ntntnt' over and over and my computer is highlighting everything. Is there any examples of how these modifiers might be used in relation to the combinations I need? There are no code examples in this manual?

I would appreciate any examples. Thank you.

You are pressing them for 1 second!

Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.press('n');
delay(10);
Keyboard.releaseAll();

There are examples supplied in the IDE :
Files -> Examples -> USB

Thank you for your quick answers. Sorry I miss typed and meant (10) not 100 ;
The problem is the code:
Keyboard.press('KEY_SHIFT');
Keyboard.press('n');

is still returning 'NT' and not (Shift +N). I don't understand Where is the 'T' coming from? Sorry if it is a stupid question. Thanks.

Post your full updated code, please.

Try that code.

Thanks. Here is my full code to test the 'shift +n'. Not sure if it is the best way to do it. I still need to figure out the other combinations posted above.

#include <Keyboard.h>
long count;
void setup(){
Serial.begin(9600);
Keyboard.begin(); // Initialise the library.

}

void loop()
{
count = count+1;
Serial.println(count);

if (count == 8500){
Keyboard.press('KEY_SHIFT');
Keyboard.press('n');
delay(10);
Keyboard.releaseAll();
count= 1;
}

}

I just tried this and it is still returning 'NT'. Not sure what is wrong. Thanks again.

Also, I do not see the 'Windows' key listed in the modifiers is it still possible to use this? I also need 'Windows + 1' to be initiated. Thanks.

There is no such thing as KEY_SHIFT and it also should not have single ticks around it. Try

Keyboard.press(KEY_LEFT_SHIFT);

I further suggest that you use a safety mechanism so your PC doesn't get spammed. I use what I call a safetyPin that must be tied to GND for the code to be able to send keys.

#include <Keyboard.h>

const byte safetyPin = A0;

long count;
void setup() {
  Serial.begin(57600);
  while (!Serial);
  Keyboard.begin(); // Initialise the library.

  pinMode(safetyPin, INPUT_PULLUP);

}

void loop()
{
  if (digitalRead(safetyPin) == HIGH)
  {
    return;
  }

  count = count + 1;
  Serial.println(count);

  if (count == 8500) {
    Keyboard.press(KEY_LEFT_SHIFT);
    Keyboard.press('n');
    delay(10);
    Keyboard.releaseAll();
    count = 1;
  }
}

And the Windows key is KEY_LEFT_GUI or KEY_RIGHT_GUI.

Sorry for the delayed reply. Thank you for the answer and suggestions. This all worked perfectly now!

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