Trinket M0: Send key commands only to a speficic application

Hello world

I'm in the middle of a project, where I build a mute button for a microphone on my windows PC. I'm using the program "MicMute" to set a shortcut that I send from my Arduino Trinket M0 when I press a physical button. My problem now is, that I use RDP remote desktop for work and my key commands from my Arduino end up on the remote desktop (only when I'm in the window of the remote desktop). My question is, can I somehow program my Arduino to send the key commands only to a specific application (MicMute)? Other solutions are also welcome.

SOLUTION: I installed the MicMute application on the PC I had remote acces too and did set it up exactly the same way I did on my home computer. This way it works as intended (just on the remote desktop).

The code I use (not original from me):

#include "Keyboard.h"

int buttonNum[5] = {3, 4, 2, 0, 1};
int buttSelect = 0;
int buttFlag = 0;
void setup() {

  Serial.begin(115200);
  for (int x = 0; x < 5; x++) {
    pinMode(buttonNum[x], INPUT_PULLUP);
    attachInterrupt(buttonNum[x], buttPressed, LOW);
  }

  Keyboard.begin();
}

void loop() {
  while (buttFlag == 0) {
    delay(10);
  }
  Serial.print("Button ");
  Serial.print(buttSelect);
  Serial.println(" pressed.");
  switch (buttSelect) {
    case 0:
      Command0();
      break;
    case 1:
      Command1();
      break;
    case 2:
      Command2();
      break;
    case 3:
      Command0();
      break;
    case 4:
      Command1();
      delay(1000);
      Command2();
      break;
    default:
      break;
  }
  int pressed = digitalRead(buttSelect);
  while (pressed == 0) {
    pressed = digitalRead(buttSelect);
  }

  buttFlag = 0;
}

void buttPressed() {
  buttFlag = 1;
  for (int x = 0; x < 5; x++) {
    int butt = digitalRead(x);
    if (butt == LOW) {
      buttSelect = x;
      break;
    }
  }
}


//Upload to Arduino
void Command0() {}

void Command1() {}

void Command2() {  
  Serial.println("Pressing CTRL+F12");
  Keyboard.press(KEY_RIGHT_CTRL);
  Keyboard.press(KEY_F12);
  delay(100);
  Keyboard.releaseAll();

  delay(500);}
void Command3() {}

void Command4() {}

I have a similar thing hooked up for certain shortcuts.

I hope to be wrong, but these operate at too low a level to do what you want… UI actions be they keystrokes or mouse clicks or simulated inputs of those from USB HID hacks are directed by the desktop OS to the UI element that has the focus.

Or grabbed for other use before being so directed - the “three finger salute” or the Nac OS keys that make Force Quit window pop up.

In fact that’s one of my shortcuts. I have that because I can never remember which keys to hold down and it’s also useful when you real keyboard decides it isn’t gonna help you out.

I don’t use the other shortcut buttons when their input would be inappropriate, that is to say when the focus is not on a UI element that would make sense.

So just don’t do that. :wink:

I hope to be wrong. Any solution will be interesting at least.

a7

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