No Keypresses being simulated.

So I wanted to troll a friend of mine (I’m sorry :slight_smile: ) and wrote this script for my Arduino Pro Micro.
The Problem is, that there are no keypresses or stuff being simulated.

#include <Keyboard.h>

void setup() {
  Keyboard.begin();
}

void loop() {
  int timer = random(30,240);
  Keyboard.print("timer");
  delay(timer * 1000);
  int mode = 0;
  if(mode = 1){
    heavyAction();
  }else{
    lightAction();
  }
}

void heavyAction(){
  int action = random(0,3);
  if(action = 0){
    heavyTab();
  }else if(action = 1){
    heavyDelete();
  }else if(action = 2){
    heavyEnter();
  }else{
    altf4();
  }
}

void lightAction(){
  int action = random(0,3);
  if(action = 0){
    arrow();
  }else if(action = 1){
    enter();
  }else if(action = 2){
    randKey();
  }else{
    del();
  }
}

void heavyEnter(){
  Keyboard.press(KEY_RETURN);
  delay(500);
  Keyboard.releaseAll();
}

void heavyTab(){
  Keyboard.press(KEY_TAB);
  delay(500);
  Keyboard.releaseAll();  
}

void heavyDelete(){
  Keyboard.press(KEY_LEFT_ALT);
  Keyboard.press(KEY_RETURN);
  delay(5);
  Keyboard.releaseAll();
}

void altf4(){
  Keyboard.press(KEY_LEFT_ALT);
  Keyboard.press(KEY_F4);
  Keyboard.releaseAll();
  delay(1000);
  Keyboard.press(KEY_RETURN);
  Keyboard.releaseAll();
}

void arrow(){
  int x = random(0,4);
  if(x < 1){
    Keyboard.press(KEY_UP_ARROW);
  }else if(x < 2){
    Keyboard.press(KEY_DOWN_ARROW);
  }else if(x<3){
    Keyboard.press(KEY_LEFT_ARROW);
  }else {
    Keyboard.press(KEY_RIGHT_ARROW);
  }
  Keyboard.releaseAll();
}

void enter(){
  Keyboard.press(KEY_RETURN);
  Keyboard.releaseAll();
}

void randKey(){
  int y = random(141,172);
  Keyboard.print(String(y, BIN));
  Keyboard.releaseAll();
}

void del(){
  Keyboard.press(KEY_LEFT_ALT);
  Keyboard.press(KEY_BACKSPACE);
  Keyboard.releaseAll();
}
  if(mode = 1){

etc.

= is assignment == is comparison

  int timer = random(30,240);
  delay(timer * 1000);

This will most probably create an overflow...

Try

delay(timer * 1000L);

Whandall:   int timer = random(30,240);   delay(timer * 1000);

This will most probably create an overflow...

Try

delay(timer * 1000L);

So it really appears to be the delay. But still without your option it does not work. changed it to 5000 and everything works properly

So now I just called delay(timer*1000); 10 times in a row, it works :D