Problem with keyboard.h!

Hi there, i have a problem with Keyboard library . I have arduino leonardo. I wrote this code, and keyboard doesn't typing , but mouse.click function works .

#include <Keyboard.h>
#include <Mouse.h>

bool q = true;
bool w = true;

int sensorValue = 0;

void setup() {
  Serial.begin(9600); 
  pinMode(A0, INPUT);
  Keyboard.begin();
  Mouse.begin();
}

void loop() {
  sensorValue = analogRead(A0);
  
  if(int(sensorValue) == 1017 && q == true) {
    Keyboard.press('a');
    delay(10);
    Keyboard.releaseAll();
    Mouse.click();
    Serial.print("Test2");
    q = false;
    w = true;
    
  }
  else if(int(sensorValue) == 77 && w == true) {
    Serial.print("Test");
    Keyboard.press('o');
    delay(10);
    Keyboard.releaseAll();
    q = true;
    w = false;
  }
  delay(1);
}

Why Keyboard.h doesn't work ? Please help !

Have you tried printing the values returned by analogRead to see if they're what you expect?
I wouldn't use == in this case; better you use a range.

Analogue readings are notoriously noisy.

I printed this values with Serial.print . And values +/- stable . Then i wrote code with this values. I have this thing:
изображение_2021-10-31_174357

And this thing have fixed positions. All works but not keyboard . I don't know why . Yes ok i rewrite code with using range , but will it fix keyboard ?

Hello
Post the schematic of your project with all components used.

Hi there my scheme looks like this


This black scheme on the left side, this is type of connection that i use for my "potentiometer" . This is thing from USSR , and it's like potentiometer with 10 fixed positions , in my build i use only 7 . But i didn't find scheme with 7 buttons (It works like 7 buttons) , only 4 buttons , but you just imagine other 3 buttons and resistors.

And my 7 resistors doen't have the same Ω value .
From first to last -> 1,2KΩ ; 1KΩ ; 1,5KΩ ; 1,1KΩ ; 1KΩ; 1KΩ; 910Ω
And one more resistor connected to GND: 10KΩ