Author Topic: Digispark Keyboard sendKeyStroke how to release each button  (Read 181 times)

skwyun

  • Newbie
  • *
  • Posts: 1
Digispark Keyboard sendKeyStroke how to release each button
« on: October 11, 2017, 08:47:29 am »
Hi. I tried to make 2-key keyboard with my digispark, but I can't simultaneously push the twice button.
I tried to use the buffers but I didn't know how to do it.
Because the sendKeyboard() holds the button continuously pressed at the delay(), it uses sendKeyPress() to hold the button pressed.
However, I would like to find a way to keep the two buttons at the same time, because I only know how to release the buttons. This is a translation using a translator. :D
Code: [Select]
#include <Digikeyboard.h>

typedef struct {
  byte Pin;
  byte Key;
  boolean Press;
} BUTTON;

void ButtonRead(BUTTON* Btn){
  int State = digitalRead(Btn->Pin);
  if(State==HIGH&&State!=Btn->Press){
    Btn->Press = State;
    DigiKeyboard.sendKeyPress(0);
  }
  else if(State==LOW&&State!=Btn->Press){
    Btn->Press = State;
    DigiKeyboard.sendKeyPress(Btn->Key);
  }
}

BUTTON Btn1 = {2,KEY_Z,false};
BUTTON Btn2 = {0,KEY_X,false};

void setup() {
  pinMode(0,INPUT_PULLUP);
  pinMode(2,INPUT_PULLUP);
  DigiKeyboard.sendKeyStroke(0);
}

void loop() {
  ButtonRead(&Btn1);
  ButtonRead(&Btn2);
  DigiKeyboard.delay(10);
}
« Last Edit: October 13, 2017, 09:20:44 pm by skwyun »