Do a certain action depending on which window you are in - Arduino Leonardo

Hello, everyone!
I have an Arduino Leonardo that interfaces with a rotary encoder that when pressed changes modes. Is there a way for the Arduino to know what window it is in and execute a given command based on that?

This is my code:

#include <HID-Project.h>

// Rotary Encoder Inputs
#define inputCLK 1
#define inputDT 2
#define inputSW 3

int currentStateCLK;
int previousStateCLK;
int mode = 1;
int maxModes = 3;

void setup() { 
  // Set encoder pins as inputs  
  pinMode (inputCLK,INPUT);
  pinMode (inputDT,INPUT);
  pinMode(inputSW, INPUT_PULLUP);

  // Setup Serial Monitor
  Serial.begin (9600);
  Consumer.begin();
  Keyboard.begin();

  // Read the initial state of inputCLK
  // Assign to previousStateCLK variable
  previousStateCLK = digitalRead(inputCLK);
} 

void loop() { 
  // Read the current state of inputCLK
  currentStateCLK = digitalRead(inputCLK);

  // If the previous and the current state of the inputCLK are different then a pulse has occured
  if (currentStateCLK != previousStateCLK){ 
    // If the inputDT state is different than the inputCLK state then 
    // the encoder is rotating counterclockwise
    if (digitalRead(inputDT) != currentStateCLK) { 
      rotateRight();
    } else {
      rotateLeft();
    }
  } 
  // Update previousStateCLK with the current state
  previousStateCLK = currentStateCLK;
  
  if(!digitalRead(inputSW)){
    changeMode();
    delay(300);
    }
}

void changeMode(){
  mode = (mode % maxModes)+ 1;
  }


void rotateRight() {
  switch(mode){
    case 1:
    //Ctrl + Tab
    Keyboard.press(KEY_LEFT_CTRL);
    Keyboard.press(KEY_TAB);
    Keyboard.releaseAll();
    break;
    case 2:
    //Desplazarse entre pestañas de IntelliJ/Webstorm
    Keyboard.press(KEY_LEFT_ALT);
    Keyboard.press(KEY_RIGHT_ARROW);
    Keyboard.releaseAll();
    break;
    case 3:
    //Desplazarse en YT
    Keyboard.write(KEY_RIGHT_ARROW);
    break;
    } 
}

void rotateLeft() {
  switch(mode){
    case 1:
    //Ctrl + SHIFT + Tab
    Keyboard.press(KEY_LEFT_CTRL);
    Keyboard.press(KEY_LEFT_SHIFT);
    Keyboard.press(KEY_TAB);
    Keyboard.releaseAll();
    break;
    case 2:
    //Desplazarse entre pestañas de IntelliJ/Webstorm
    Keyboard.press(KEY_LEFT_ALT);
    Keyboard.press(KEY_LEFT_ARROW);
    Keyboard.releaseAll();
    break;
    case 3:
    //Desplazarse en YT
    Keyboard.write(KEY_LEFT_ARROW);
    break;
    }
}

No.

Only if the device that controls the changing of the window can signal to the Arduino what window is currently active.

@missdrew had a more concise answer.

The device is a PC and I don't know if that can be indicated. I was thinking maybe you can use C++'s getWindow() function or something similar.

Maybe I wasn't so clear. For example, if you are in Chrome, which I sent the key combination Ctrl + Tab to the right, to go navigating between tabs.

So you want the "if you are in Chrome" part. I think you will need a program on the PC that will send a message to the Arduino's serial port each time the input focus is moved to a different window. You need to learn PC programming or find someone who knows how to do it already.

No you were perfectly clear.

It might be simpler to pass the encoder data to the program on the PC over serial and let it figure out what keystrokes to send.

I understand. Is there any program to do this?

Is there a way to do it by code?