Hi everyone, I'm currently working on a 2-key keypad to play rhythm games using a Pro Micro with the keyboard.h library.
I finished yesterday the coding, but I have an issue: one key should send the "x" keystroke an the other one the "z" one, but instead the x one sends LShift + "/" keystrokes and the other one sends "+" keystroke.
How do I solve this?
Here is the code:
#include <Keyboard.h>
#include <KeyboardLayout.h>
#include <Keyboard_da_DK.h>
#include <Keyboard_de_DE.h>
#include <Keyboard_es_ES.h>
#include <Keyboard_fr_FR.h>
#include <Keyboard_it_IT.h>
#include <Keyboard_sv_SE.h>
//Código propio
#define botonZ 16
#define botonX 14
#define ledZ 10
#define ledX 6
#define ledG 7
int pressX = 0;
int pressY = 0;
int pressG = 0;
void setup() {
//Setup propio
pinMode(ledZ, OUTPUT);
pinMode(ledX, OUTPUT);
pinMode(ledG, OUTPUT);
pinMode(botonZ, INPUT);
pinMode(botonX, INPUT);
Keyboard.begin();
}
void loop() {
int z = digitalRead(botonZ);
int x = digitalRead(botonX);
//Configuración del botón/switch que emulará el keystroke "z"
if(z==1){
digitalWrite(ledZ, HIGH);
Keyboard.press("z");
}
else{
digitalWrite(ledZ, LOW);
Keyboard.release("z");
}
//Configuración del botón/switch que emulará el keystroke "x"
if(x==1){
digitalWrite(ledX, HIGH);
Keyboard.press("x");
}
else{
digitalWrite(ledX, LOW);
Keyboard.release("x");
}
}
Does it actually send two keystrokes for the "x" or does it send the keystroke for the character you get if you push shift and "/" on your keyboard?
What keyboard layout are you using? The default is the US keyboard layout. If you're using another one you have to specify that.
Also, when i try using the spanish layout, it gets even worse; it happens the same but with "=" instead of "/" and it presses shift about 15 times per press
Then you don't know if the Arduino is the problem.
There is a ton of documentation on that site. Basically let it sniff on the USB interface you connect the Micro to and it will show you what the Arduino sends. I would expect you to see 0x1b and 0x1d scan codes. If these codes are transferred but you see something different on you PC you have to fix your PC software.
Ok, so I have installed wireshark and USBPcap.
I opened the app and entered in the USBPcap1, which is the one where my pro micro is connected, and it looks like this