¡Hola a todos!
Tengo un Arduino Leonardo que interactúa con un codificador rotatorio.
¿Hay alguna manera de que Arduino sepa en qué ventana se encuentra y ejecute un comando determinado en función de esto?
Por ejemplo, si se encuentra en Chrome, que envíe la combinación de teclas Ctrl + Tab al girar a la derecha, para ir navegando entre pestañas.
Este es mi código:
	
	
	
		
				
			Tengo un Arduino Leonardo que interactúa con un codificador rotatorio.
¿Hay alguna manera de que Arduino sepa en qué ventana se encuentra y ejecute un comando determinado en función de esto?
Por ejemplo, si se encuentra en Chrome, que envíe la combinación de teclas Ctrl + Tab al girar a la derecha, para ir navegando entre pestañas.
Este es mi código:
		C:
	
	#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;
}
}
    }
} 
   
				 
						 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		