HID_Keyboard - Multiple key presses

Hi all,

Complete newbie here, but trying to get my head round everything.

I've just received a Bare Conductive Touchboard, and have just managed to get it working as a keyboard using the code found below.

HID_Keyboard · GitHub.

However what I'm trying to accomplish is for each trigger to actually do 2 key presses at once.

Example E0 would then trigger 'Z + KEY_RIGHT_ARROW'
E1 Would then trigger 'A + KEY_RIGHT_ARROW'

First of all, is this possible by modifying the 'const char keymap'
const char keyMap[12] = {'J', 'U', 'H', 'Y', 'G', 'T', 'F', 'D', 'E', 'S', 'W', 'A'};

If not, is it possible to add a press and release function to this code so on press it would do 'Z' and on release it would do 'KEY_RIGHT_ARROW'?

Sorry for my lack of knowledge on the matter but have been chucked in the deep end at work, and am looking for an easy solution.

Many Thanks

That board is not used a lot, I didn’t know it.

This is the touch board, made by “Bare Conductive” : https://www.bareconductive.com/shop/touch-board/.
Do they have Arduino code on their website? or perhaps schematics?

Sparkfun sells it as well: Bare Conductive Touch Board - DEV-13298 - SparkFun Electronics.
And Sparkfun has a schematic :stuck_out_tongue:
It is a very expensive Arduino Leonardo compatible board with the MPR121 for touch and a VS1053b for sound and a SD memory card socket.

Was it a Christmas gift ? I think that money could be spent in a better way.
When you want to make music with a simple Arduino board, you could try the Mozzi library: http://sensorium.github.io/Mozzi/.

Your link to the gist seems to be a sketch from “Bare Conductive”, did you upload that ?
Bare Conductive do have their own Github section.
I suggest to use their MPR121 library, and try a few of the examples that come with it: https://github.com/BareConductive/mpr121

It seems that there are 12 pins, and the examples assume that the pins are 0 to 11. The MPR121.isNewTouch() and the MPR121.isNewRelease() tell if that specific pin was touched or released.

For a quick and dirty solution, you could try the Keyboard.write() to send a key at pressing and at releasing.

Using the Keyboard.press() when pressing a button and a Keyboard.release() when releasing a button is better. You might need those two functions when you want a combination of keys pressed at the same time.

The key ‘E’ is number 8 ?
You could filter number 8 out of it, and let the rest do the old sketch.

for( int i=firstPin; i<=lastPin; i++)
{
  if( MPR121.isNewTouch( i))
  {
    digitalWrite( LED_BUILTIN, HIGH);

    // test if it is our special number 8 key 'E'
    if( i == 8)
    {
      Keyboard.write( 'Z');  
    }
    else
    {
      Keyboard.press( keyMap[i]);
      if( !holdKey) 
        Keyboard.release( keyMap[i]);
    }
  } 
  else if( MPR121.isNewRelease( i))
  {
    // test if it is our special number 8 key 'E'
    if( i == 8)
    {
      Keyboard.write( KEY_RIGHT_ARROW);  
    }
    else
    {
      if( holdKey) 
        Keyboard.release(keyMap[i]);
    }
    digitalWrite(LED_BUILTIN, LOW);
  }
}