Sensors to Arduino Micro to HC-05 Bluetooth to PC using keboard.press commands

Nick_Pyner:
I know nothing about the keyboard, and I note the conspicuous absence of code. At a guess, you might be sharing the COM port between keyboard and bluetooth. This may be fixed by taking bluetooth off the hardware serial and using software serial instead. Software serial is never a good idea as it clogs up Arduino but the human interface will probably disguise that.

OK, here is the code:

#include <CapacitiveSensor.h>
#include <Encoder.h>
#include <Keyboard.h>

int threshold = 150; //

//ENCODER
long oldPosition  = -999;

//ENCODER---------
Encoder myEnc(2, 3);
///

//setting the capacitive sensors 
CapacitiveSensor   cs_4_5 = CapacitiveSensor(4,5);   
CapacitiveSensor   cs_4_6 = CapacitiveSensor(4,6);    
CapacitiveSensor   cs_4_7 = CapacitiveSensor(4,7);    
CapacitiveSensor   cs_4_8 = CapacitiveSensor(4,8);    
CapacitiveSensor   cs_4_9 = CapacitiveSensor(4,9);    

void setup()                    
{
   //begin serial communication
   Serial1.begin(9600);
   //begin keyboard
   Keyboard.begin();
}

void loop()                    
{
    //update the encoder for the position.
    updateEncoder();
    //update capacitive sensors to find out if they have been touched. 
    updateCapacitiveSensors();
}

void updateEncoder(){
  long newPosition = myEnc.read();
  if (newPosition != oldPosition) {
    
    //I am only reading every 12 steps or it's too quick
    if(newPosition % 12 ==0){
       Serial1.println(newPosition/4);
       if(newPosition > oldPosition){
        //GOING COUNTERCLOCKWISE
        Keyboard.write(216); //left arrow
       }
       else{
        //GOING CLOCKWISE
        Keyboard.write(215); //right arrow
       }
    }
    oldPosition = newPosition;
  } 
 }

void updateCapacitiveSensors(){
    long total1 =  cs_4_5.capacitiveSensor(30);  
    long total2 =  cs_4_6.capacitiveSensor(30);  
    long total3 =  cs_4_7.capacitiveSensor(30);  
    long total4 =  cs_4_8.capacitiveSensor(30);  
    long total5 =  cs_4_9.capacitiveSensor(30);  
    
    Serial1.print("\t");                    // tab character for debug windown spacing
    Serial1.print(total1);                  // print sensor output 1
    Serial1.print("\t");
    Serial1.print(total2);                  // print sensor output 2
    Serial1.print("\t");
    Serial1.print(total3);                  // print sensor output 3
    Serial1.print("\t");
    Serial1.print(total4);                  // print sensor output 4
    Serial1.print("\t");
    Serial1.print(total5);                  // print sensor output 5
    Serial1.print("\t");
           
    if(total1>threshold){
      Keyboard.press(128); 
      Keyboard.press(130); 
      Keyboard.press('e'); 
      delay(500);
      Keyboard.releaseAll();
    }
    else if(total2>threshold){
      Keyboard.press(128); 
      Keyboard.press(130); 
      Keyboard.press('n'); 
      delay(500);
      Keyboard.releaseAll();
    }
    else if(total3>threshold){
      Keyboard.press(128); 
      Keyboard.press(130); 
      Keyboard.press('w'); 
      delay(500);
      Keyboard.releaseAll();
    }
    else if(total4>threshold){
      Keyboard.press(128); 
      Keyboard.press(130); 
      Keyboard.press('b'); 
      delay(500);
      Keyboard.releaseAll();
    }
        else if(total5>threshold){
      Keyboard.press(128); 
      Keyboard.press(130); 
      Keyboard.press('a'); 
      delay(500);
      Keyboard.releaseAll();
    }
  }

The USB (COM6) comes up as a different COM port to the HC-05 (COM7 & COM8). I have also tried to use Software Serial with no luck.

sterretje:
The Micro uses native USB. The keyboard functions only work with that.

Serial simulates a serial port via USB and has no relation with the RX and TX pins on the Micro; those are Serial1. They don't interfere with the upload (contrary to e.g. an Uno or Mega).

If you managed to make the HC-05 show as a keyboard, have you tried something simple like

Serial1.print('1');

Which in an editor should show a one (if it works).

OK, does that mean I was correct that the keyboard.press functions only work through USB?
As you can see in my code, I am using Serial1.
I am able to connect to the HC-05 using RealTerm and also on my phone, I get a stream of data on the Outgoing port and CPS# goes from ~1200 down to ~100 when the capacitive sensor is touched so that tells me there is some sort of communication between the sensors, arduino and HC-05.