I solved it. The code I used and that works is
void setup() {
Serial.begin(9600);
pinMode(10, INPUT_PULLUP);
delay(4000);
}
void loop() {
if (digitalRead(10) == HIGH) {
delay(10);
} else {
Keyboard.set_key1(KEY_F11);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
delay(1000);
}